Jump to content
Pixrael

A Markup API in the kingdom of Processwire

Recommended Posts

The recent introduction of the Markup Regions has caused some excitement in our community, mainly for the simplicity of the proposal to output our markup, but for the various opinions about how to select and modify the regions, maybe it should not be the definitive solution. Perhaps the most correct option is to think this output strategy in the "Processwire style". Something open and versatile.

The solution could be: Have the layouts files (main.php) as our "Markup Database" and then with the templates files (home.php) we can do "CRUD operations" on it before the output, using for that a jquery/processwire like API. This could be a powerful way like the current excellent API solution to manipulate the data.

Where $markup come from the layout file "_main.php", in our templates files we'll can do:

<?php $markup->find('#sidebar').prepend(' ?>
  <div class="foobarcontainer">
    <h3>Hello <?php echo $page->foo ?></h3>
    <p><?php echo $page->bar ?></p>
  </div>
<?php '); ?>
<?php if ($hidecomments) $markup->find('.comment').addclass('close'); ?>
<?php $markup->find('#sidebar .contact ul').remove(); ?>

Etc. Think about the possibilities, it will no longer be necessary to define regions, the regions are any part of the document

It's just an idea, maybe is a really hard to-do solution, but will be perfect for the Processwire ecosystem as the direct-delayed output workflow. In GitHub already are several php libraries for select DOM elements using any css selector in a jquery like style. 

Share this post


Link to post
Share on other sites

As someone maintaining a project with lots of different frontend templates I'd imagine you'd get into trouble way fast with such an approach. As soon as you've more than a few of those calls in your code base it'll get hard to reason about what's currently visible and what's not part of the markup, as you've to go through all those steps in your head. There's no scope of interaction. Each of those calls could potentially change everything in your page. I don't think it's a good idea to let you junior dev remove some class in some part of your website, which by accident could break other parts of it because the class is duplicated. With the current markup implementation you're at least bound to a (hopefully limited) number of named regions. I imagine it a bit like those early jquery webapp javascript files: a mess of spaghetti code which nobody but the creator can understand in a reasonable timeframe.

  • Like 3

Share this post


Link to post
Share on other sites

I agree with you, I was just trying to think of a way to freely act over the elements. Sorry for this crazy post ;-)

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By rushy
      Hello. I have recently adopted PW markup regions and really like this way of working. However, I am also trying to learn how to use Ajax and I am not sure of a good way to use the two together. Has anyone got any experience, tips or hints on using them together? For ajax -  I've used a simple scheme where I have a "webservice" template and page that handles Ajax requests and returns the appropriate content wrapped with some markup for the requesting page. I have markup regions enabled and all my pages (bar webservice) include a _main.php which brings in the headers, a default body and the footer. My javascript intercepts the page links and does my ajax call to webservice and that sends back the appropriate markup which is then placed by in the div #body defined in _main.php.  Does this seem a reasonable way to work? I guess I am looking for some advice before I invest too much time going the wrong way!
      Any guidance, remarks,  comments, or a nudge in the right direction greatly appreciated.
      Paul
    • By Moritz Both
      Greetings!
      For our PW project we use markup regions and, for one template, url segments. The documentation recommends throwing a new Wire404Exception() from the template when the code concludes that the url segments from the request are invalid, and so we do.
      However, the 404 page is not displayed properly. Viewing the page source in the browser we can see that the original, unmodified markup region contents from our _init.php file is prepended to the correct html output, messing the whole page up.
      Any advice is greatly appreciated.
    • 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?
    • By EyeDentify
      I as have been a bit confused for some time about how the "Markup Regions" functionality in Processwire worked.
      But i have know read a bit more and think that i am getting to grips with it. And Markup Regions is going to be huge.

      To aid me in understanding Markup Regions better i started to read the Source code for the new "Regular" theme in conjunction with the Blog about the markup regions.
      It helped me a great deal to understand the basics and more fine details of it.

      A tip is to open both links and use the Source code of the "Regular" theme while reading the blog post.
       
      The Source code:
      https://github.com/processwire/processwire/blob/dev/site-regular/templates/_main.php
      The Blog post:
      https://processwire.com/blog/posts/processwire-3.0.62-and-more-on-markup-regions/
       
      I hope this could help others starting out with markup regions.
      Just take it slow and read it a couple a times and soon you will see the greatness of markup regions.

      /EyeDentify 
    • 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!
       
×
×
  • Create New...