psy

Regions on basic page

Recommended Posts

I am using regions with the tag <region id="whatever"> in the _main.php file. Config file is set up as follows:

$config->useMarkupRegions = true;
$config->prependTemplateFile = '_init.php';
$config->appendTemplateFile = '_main.php';

When I use a page template that changes a region, all goes well. However, I set up the _main.php file to reflect the output for a basic page. The basic-page.php template needed no customisation so was simply as follows:

<?php namespace ProcessWire;
?>

When a page with the basic-page template was output, all the <region> tags remained in the HTML, ie were not stripped.

When I added a customised region to the basic-page.php template, all the <region> tags were stripped from the output _main.php HTML.

Did I do something wrong or is this a bug?

Using ProcessWire 3.0.63 © 2017 

 

Share this post


Link to post
Share on other sites

Quick workaround... in _main.php add

<region id="dummy"></region>

in basic-page.php add

<region id="dummy"></region>

Seems PW needs a region in the page template to kick-start the process.

  • Like 3

Share this post


Link to post
Share on other sites

is there still a bug? Same problem here on Processwire 3.0.69


$config->useMarkupRegions = true;
$config->prependTemplateFile = '_main.php';

in _main.php
 

<?php namespace ProcessWire; include_once("./_init.php"); ?>

....

<region id="dummy">
  <h1><?php echo $title; ?></h1>
  <?php echo $teaser; echo $content; ?>
</region>


in basic-page.php

<?php namespace ProcessWire; ?>

<p pw-prepend="dummy">
  123
</p>

 

Voila:

Unbenannt33333333.PNG.fb02cf29cca6dafd8eb0865dee9dd213.PNG

  • Like 1

Share this post


Link to post
Share on other sites

@maxf5 Did you try it with <pw-region> too? Sure, they should be the same, but still...

To tell the truth, I never really understood why having all these variations of the same thing is good. It just makes things more confusing, more time to debug but adds no additional feature. It's like having similarly named methods doing the same thing. Well, at least they are supposed to do the same ;) 

Share this post


Link to post
Share on other sites

@szabesz , yes.. some problem with <pw-region>

in _main.php

<pw-region id="something">
...
</pw-region>


in basic-page.php

<p pw-append="something">
  12123123123
</p>

and you get:
Unbenannt33.PNG.26ad4c103b1394b8055261c048ef5f4d.PNG

Settings:
$config->useMarkupRegions = true;
$config->prependTemplateFile = '_main.php';
ProcessWire 3.0.69 

PHP VERSION 7.0.18

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Is there any solution to make MarkUpRegions work when you have your general markup in prepended or appended files, @ryan ?

I am really excited about this feature and cant use it so far

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jtborger
      Hi,
      Yesterday I found out about the relatively new markup regions functionality and I love it. The ease of use and simplicity is just what I think is typically ProcessWire and is why Im still happy I chose for PW four years ago when changing CMS/CMF. So thanks Ryan for your vision and all you put into it.
      That said, Im running into an issue I'm not sure what to think of it.
       
      I have enabled markup regions in config.php and it does what I suppose it should: it replaced and all. Very neatly. 
      The only thing I discovered is that while Im debugging some issues and I use var_dump to echo some stuff, it does that two times in a row. And this only happens when useMarkupRegions is enabled.
      I dont get this, does it mean the template file gets called twice (and thus the script is run twice?) or is it only displayed twice, where the first time most output is erased and /or replaced by the substituted output?
      I don't really get whats going on there. Is this behavior normal when using markup regions?
      Thanks!
       
    • By mike62
      I'm working on a page and it's showing up differently when I'm logged in. It's not that a field is set to private or anything, because it's still pulling data from that field. It looks like the "public" view is simply using an old version of the template (home.php), and the logged-in view is using the current version of home.php. See attached screenshots.
      Is there something that caches template files? Is there a way to force it to use the most recent version of the template?
      EDIT: I found the Pro Cache module and cleared it. That seemed to help. 
      Thanks,
      -Mike


    • By mike62
      I am new to PW, and am trying to get an image to display, from a field in my template. Here's the code I'm using:
      <?php $image = $page->home_header_image; echo "<img src='{$image->url}' alt='{$image->description}' />"; ?> I'm following the tutorial on this here.
      When I save the template and reload the page, the path to the image is incomplete. If just echoes:
      <img src="/site/assets/files/1/" alt=""> It omits the name of the image, at the end of the path.
      Here's the site I'm working on:
      http://dev.delucaswpg.webfactional.com
      A couple caveats:
      I'm using ProcessWire 2.3.0 (tried updating the site and everything went berserk because of some plugin dependencies; point being: I can't update to the latest PW). I tried using the ->size thing and it gave me an error, saying it couldn't use 'size' in this context. Which I also thought was weird. Any ideas? Thanks!
    • By Violet
      I originally created my template files thinking I'd only ever need 3 and not worrying about if I repeated bunches of common code there (yes, bad practice, I know). I figured I'd just manually/copy-paste to change any common code in all 3 as needed. So of course, fast-forward awhile, and I'm now up to 6 template files with possibly a few more to come, and decided it was high time I made the switch to keep the common parts in their own unique files for ease of editing. So I therefore went back and read Ryan Cramer's tutorial "How to Structure Your Template Files".
      OK. I tried out the "includes" command mentioned in the tutorial on a test template. The resultant web page physically functions as expected, but my question here is, "Is the practice I'm showing below OK in terms of variable usage?" If not, what approach should I be using? 
      I've tested it out and the variables do populate as expected in the final result, but is it OK for me to do it like this or is there the chance that some of the variables won't be passed properly?
      Here is what I  mean (only the relevant portions of code shown to illustrate):
      ... <aside> <h3>Three Random Posts</h3> <!-- get the list, then display it --> <?php $itempages = $pages->find("template=my-post"); $shortlist = $itempages->getRandom(3); $shortlist->shuffle(); $itempagezero = $shortlist->eq(0); $itempage1 = $shortlist->eq(1); $itempage2 = $shortlist->eq(2); ?> <?php include("./INC_displaylist.php"); ?> </aside> <?php include("./INC_footer.php"); ?> </body> </html>
      The possible issue here is that the INC_displaylist.php file outputs field data from $itempagezero, $itempage1, and $itempage2. Is that OK? I wanted to split the variable assignments and the output separately. This is because, based on the exact template I'm using, I will sometimes choose to populate $itempages via different selectors in the $pages->find command in different template files, although all templates will display an identically-formatted list of 3.
      By contrast, I wouldn't expect any variable issues with including the INC_footer.php file as shown above, since I'm not using any variables in the footer that aren't first referenced in that same footer.
      So am I doing it OK here or should I be populating these variables somewhere else to ensure they're recognized properly by INC_displaylist.php? If I need to do it somewhere else, where should I populate these?
    • By Peter Knight
      Is the template name a value which I can display?
      I've read the API docs re. template names and tried a few things including below but nothing works so far.
      Template is: {$page->$template->name} FYI I'm building a small 'helper' section in a footer which is only visible to admins and it will display page ID, template name and a link to edit the page.
      Everything working apart from displaying the template name.