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 5

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 mjut
      Hello!
      I am trying to get some extra css-file into my admin templates. I managed to modify my admin.php to this:
      <?php namespace ProcessWire; require($config->paths->adminTemplates . 'controller.php'); echo "<link rel='stylesheet' type='text/css' href='" . $config->urls->templates . "css/admin.css'>"; By doing so, the css <link> is added to the very end of each parsed admin-html. (right AFTER the closing </body> tag.)
      That causes some trouble. e.g. the page tree is not displaying any more. Although, other pages are working - like the edit form of a page.
      My question: is there a correct way of adding my extra css to the admin area?
      Thanks for you help!
      Stephan
       
    • By karian
      I don't know why multiple instances (repeater_repeat_columns1, repeater_repeat_columns2, ...) of my repeater field are displayed inside Template field (see image).
      Is there a way to clean/reset it ?
       

    • By psy
      I'm combining two PW sites into one, Site A into Site B.
      At each step, I did it bit by bit as the 'all at once' approach failed.
       
      First, I exported all the fields from Site A and imported into Site B. Any field types not supported by import/export, eg FieldtypeOptions I manually recreated. All good.
      Next I exported all the templates from Site A and imported them into Site B and copied across their associated template files. All good.
      Finally I exported the pages I needed from Site A into Site B - again, bit by bit to ensure it all went smoothly.
      From the admin side, it all looked and worked perfectly.
      Front end was a totally different story. All existing pages in Site B worked as expected. NONE of the pages imported from Site A displayed. They all ended in a redirect loop with no errors in the PW logs or Tracy Debugger.
      After some trial-and-error, I finally got it working with:
      - create a new template in Site B admin with no associated template file and just a title field
      - import the fields from the imported Site A template into the newly created template (both on Site B)
      - copy the Site A php template file into a new file that matched the new PW Site B template name and save in Site B site/templates
      I can deal with the above workaround. Just curious to know if I did something wrong or if the template import/export feature is problematic?
       
      ### Solution:
      While the export/import was a slow process, turned out the front end redirecting issue was unrelated. For reasons unknown, all templates marked as HTTPS only were the ones redirecting, ie all templates from Site A. Finally solved it by changing the $config->https to true in site/config.php
      Now the pages display correctly as https whether the template forces the issue or not.
       
    • By louisstephens
      I have a repeater with a text field where I would like to use hanna code (to make it easier on the user) so the user can define the action of a image that is in the repeater. For example:
      1. The image should have an external link:
      - the user can just type in the url
      2. The image, when clicked, should be printable (using print.js)
      - the user can just type [[print_image]]
      That works just fine, but I am running into an "issue". The code I need to use to print is:
      onclick="printJS({printable: 'path_to_image', type: 'image'});" I can put that into the hanna code as plain text, but I have no idea how to get the image from the repeater item and pass to "path_to_image". Is this even possible?
    • By darrenc
      lets say, in _main.php I have some placeholder regions for content/sidebar
      <div id="content">foo</div> <div id="sidebar">bar</div> in my home.php template, maybe i don't want the sidebar div at all. But when I put in the intentionally blank code
      <region id="sidebar"></region> I simply make my sidebar div blank, it doesn't remove it.
      Q: Is there a slick way to simply nuke that div#sidebar entirely from markup?