jtborger

Using markup regions causes template to render twice?

Recommended Posts

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!

 

Share this post


Link to post
Share on other sites

Hi Karl,

Thanks for pointing this out to me. I had searched the forum and couldn't find anything about this. It seems that the issues you filed and my question here is the same thing... And Ryan's explaination seems fine, though I have one question for Ryan (hope he'll read this):

Indeed I output some stuff before doctype, which is tried to being rendered as a markup region as I understand from your comment on the issue Karl mentions above. Since it cannot be substituted, it gets displayed anyway, as I understand it.

But, why does it gets displayed the first time then anyway? It feels illogical to me to be honest. I understand that all output before doctype is seen as if it should be put in a region later on, and when not, it gets displayed. But shouldn't it be removed from output first, then searched for a region to be put in, and if not, then outputted anyway? Perhaps this logic is too advance/heavy since replacement gets done by regexes I think, but anyway.... just a suggestion. 

Perhaps I don't understand it correctly anyway so please excuse me for this... I still find it a very neat solution anyway! :)

 

Share this post


Link to post
Share on other sites

As far as I know the documentation says you should change the /sites/config.php. This also generates double output for me.

That never worked for me. I change /wire/config.php. Downside is that with every update I would need to change it again.

Share this post


Link to post
Share on other sites
11 hours ago, jtborger said:

while Im debugging some issues and I use var_dump to echo some stuff

Check out Tracy Debugger and you'll be glad you did. Then rather than using var_dump and echo you can use the bd() function in your files to get a lovely expandable dump output and the "double output" thing won't be an issue with Markup Regions.

2017-11-19_094145.png.76910436a4aada9201b89155bccc9565.png

  • Like 4

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 androbey
      Hello again! 

      Unfortunately I came across another problem. 

      I have a "regular" ProcessWire setup and want to create a separate php script. That script should be executed by a cron job and is bootstrapped with my PW setup. Main goal is to send mails which are stored in a email field. 
      My problem: I want to access a specific field from a template where only specific users have access to. Right now, the cron job is executed as "guest", of course. 

      How can I bypass this restriction, so that I have access to that specific field (it's only one email field)? 

      Does it make sense to set current user via api? 

      Hope you can help me out there.

      Cheers,
      Andreas
    • By mike62
      I'm trying to echo a field from another page, in my footer. I have a Website Settings page (id 1006) with several fields for general site settings, like store hours (field is named store_hours). In the footer, I have this:
      <?php $settingsPage = $pages->get(1006); echo $settingsPage->store_hours; ?> Shouldn't that output the contents of that field? Right now it's printing a "0" (zero) on the page.
      Elsewhere in the same footer template file, I have this code and it works fine:
      <?php $homepage = $pages->get(1); echo $homepage->body; ?> Does it have anything to do with the fact that the field is organized into one of these tabs, at the top of the page editor?
      (disclaimer: I'm new to PW, and have inherited this site from another developer; that's why I don't know how or why some of this stuff is set up the way it is).
      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?