Jump to content
Pixrael

More About Markup Regions: A Mixed Proposal

Recommended Posts

As a graphic designer I like the new options to output markup with the templates (region function and regions markup strategy) but testing them I think they could adapt a little more for ease of use. In this proposal I modify the syntax and the way of assigning the values, while I try to maintain the concept.

Next the common example, in "_main.php"

<!doctype html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!--[pw headseo]-->
        <!--[/pw]-->

        <!--[pw headstyles]-->
        <link rel="stylesheet" href="css/normalize.min.css">
        <link rel="stylesheet" href="css/main.css">
        <!--[/pw]-->

        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
        <!--[pw headscripts]-->
        <!--[/pw]-->
    </head>
    <body>
        <!--[pw header]-->
        <h1><?php echo $page->title(); ?></h1>
        <!--[/pw]-->
        
        <!--[pw body]-->
        <?php echo $page->body(); ?>
        <!--[/pw]-->
        
        <!--[pw footer]-->
        <!--[/pw]-->

        <!--[pw footerscripts]-->
        <script src="js/jquery.min.js"></script>
        <!--[/pw]-->
    </body>
</html>

then in the template file "home.php"

<!--[pw headstyles+]-->
<link rel="stylesheet" href="css/home.css">
<style>
    body {
        padding-top: 50px;
        padding-bottom: 20px;
    }
</style>
<!--[/pw]-->

<!--[pw head+]-->
<h2><?php echo $page->headline(); ?></h2>
<!--[/pw]-->

<!--[pw footer]-->
<h3>About Homepage</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec efficitur dignissim nisi nec consequat.</p>
<!--[/pw]-->

Well I'm not a programmer, I hope you understand the above. But the idea is:

  • Using html comments for regions definition, this is a standard in html, and not interfere with the DOM or with the page structure, allowing using it in document areas that are not visual. The current option basically is to use DIV but this is not correct in areas like the head tag.
  • Using the open/close tag system allow the use of IDE features for html as auto-completion, code coloring, code validation, visual previews and more. Allowing populate the initial values for regions without variables concatenation and with the previous advantage (auto-completion, code coloring, etc)
  • The pages can be render without additional Ids and class, maybe useful for debugging and can be cleaned in production with something like $config->cleanRegions = true;

It can support the current prepend, append, before, after etc regions strategy, I think its a mix of the current Region Markup. As I said I am not programmer but I think it can be implemented using Output Buffering ob_start (); ob_end_clean (); capturing the code between open/close comments tag and assigning them to the corresponding region ... If someone likes and have time to analyze and improve this idea, are welcome because I don't know how to implementing it .. sorry :-) 

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, Pixrael said:

Using html comments for regions definition, this is a standard in html, and not interfere with the DOM or with the page structure, allowing using it in document areas that are not visual. The current option basically is to use DIV but this is not correct in areas like the head tag.

I think @ryan is unlikely to switch from region attributes in tags to a different system where regions are defined using HTML comments, considering that the Markup Regions feature is already published and currently being used in its existing form.

But I do agree with your request to support a region tag that is stripped out of the final output. As you noted, that would be particularly useful for defining multiple regions inside the <head> element.

There is a GitHub feature request that covers some of this stuff: https://github.com/processwire/processwire-requests/issues/78

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, Robin S said:

But I do agree with your request to support a region tag that is stripped out of the final output.

+1 for this :) Personally I'm not a fan of turning comments into interpreted code. It is hacky and can be hard to read when you have other comments for actual note taking purposes. But maybe it's just me who feels this way :)

Share this post


Link to post
Share on other sites

I do not see the problem of using comments, especially during production. I usually use comments to identify parts of my code in the nesting nature of the DOM tree, in a format similar to:

<! -- here start the header - ->

<! -- end of the header - ->

I only propose a nomenclature to be able to easily identify the regions using a parsing code. Not in conflict with other comments used in the code.

Share this post


Link to post
Share on other sites

Continuing with the idea, to include some functionality of the current implementation:

Having in _main.php

<!---[pw foo]-->
<p>Lorem ipsum dolor sit amet</p>
<!---[/pw]-->

in template files to replace

<!---[pw foo]-->
<h2>Curabitur nec odio et elit iaculis posuere. Aenean finibus felis justo, vel porttitor tortor malesuada et.</h2>
<!---[/pw]-->

Output

<h2>Curabitur nec odio et elit iaculis posuere. Aenean finibus felis justo, vel porttitor tortor malesuada et.</h2>

in template files to prepend

<!---[pw +foo]-->
<h1>consectetur adipiscing elit</h1>
<!---[/pw]-->

Output

<h1>consectetur adipiscing elit</h1>
<p>Lorem ipsum dolor sit amet</p>

in template files to append

<!---[pw foo+]-->
<ul>
  <li>Proin iaculis feugiat tortor</li>
  <li>Vestibulum vestibulum ultricies semper</li>
</ul>
<!---[/pw]-->

Output

<p>Lorem ipsum dolor sit amet</p>
<ul>
  <li>Proin iaculis feugiat tortor</li>
  <li>Vestibulum vestibulum ultricies semper</li>
</ul>

in template files to inherit

<!---[pw foo]-->
<h1>consectetur adipiscing elit</h1>
<!---[pw ++]-->
<ul>
  <li>Proin iaculis feugiat tortor</li>
  <li>Vestibulum vestibulum ultricies semper</li>
</ul>
<!---[/pw]-->

Ouput

<h1>consectetur adipiscing elit</h1>
<p>Lorem ipsum dolor sit amet</p>
<ul>
  <li>Proin iaculis feugiat tortor</li>
  <li>Vestibulum vestibulum ultricies semper</li>
</ul>

in template files to remove

<!---[pw foo]-->
<!---[/pw]-->

And finally if the region is not declared in the template file, output the initial content.

Share this post


Link to post
Share on other sites

One has to parse those comments blocks out of the html, recursively, identify/skip real comments, follow inheritance tree, protect against vuln xss foo etc... The parsing is currently done in WireMarkupRegions.php which has a lot hardcoded and html specific stuff, so it's hard to wrap around.

If you really want this syntax, you should stick with an existing template engine like twig or mustache and replace the template tags with your custom comment-tag. Also consider FileCompilerModule...

I personally use plates...

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for your comments, I also reviewed how Ryan implemented it, from there come my idea. I currently use a Latte Engine Module, but for 90% of the web pages my clients need is too much of the view/controller model, it's a lot of work for simple things. That's why I like what Ryan did, but I need regions that be more versatile in defining where to place it in the document, that not use the classes/ids directly and be less complicated in terms of the number of directives and tags variants. Just do it simple. An illustration example: https://processwire.com/talk/topic/15582-markup-regionsidea-for-another-placement-attribute/

  • Like 2

Share this post


Link to post
Share on other sites

I do not mention it but part of my idea is because I use a lot of the code completion of my IDE, it makes me work faster and with less errors, so I hate the concatenation of variables when I write a mix of html tags with php Code .. yes I'm lazy but I love it O0

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 Mike Rockett
      Docs & Download: rockettpw/markup-sitemap
      Modules Directory: MarkupSitemap
      MarkupSitemap is essentially an upgrade to MarkupSitemapXML by Pete. It adds multi-language support using the built-in LanguageSupportPageNames. Where multi-language pages are available, they are added to the sitemap by means of an alternate link in that page's <url>. Support for listing images in the sitemap on a page-by-page basis and using a sitemap stylesheet are also added.
      Example when using the built-in multi-language profile:
      <url> <loc>http://domain.local/about/</loc> <lastmod>2017-08-27T16:16:32+02:00</lastmod> <xhtml:link rel="alternate" hreflang="en" href="http://domain.local/en/about/"/> <xhtml:link rel="alternate" hreflang="de" href="http://domain.local/de/uber/"/> <xhtml:link rel="alternate" hreflang="fi" href="http://domain.local/fi/tietoja/"/> </url> It also uses a locally maintained fork of a sitemap package by Matthew Davies that assists in automating the process.
      The doesn't use the same sitemap_ignore field available in MarkupSitemapXML. Rather, it renders sitemap options fields in a Page's Settings tab. One of the fields is for excluding a Page from the sitemap, and another is for excluding its children. You can assign which templates get these config fields in the module's configuration (much like you would with MarkupSEO).
      Note that the two exclusion options are mutually exclusive at this point as there may be cases where you don't want to show a parent page, but only its children. Whilst unorthodox, I'm leaving the flexibility there. (The home page cannot be excluded from the sitemap, so the applicable exclusion fields won't be available there.)
      As of December 2017, you can also exclude templates from sitemap access altogether, whilst retaining their settings if previously configured.
      Sitemap also allows you to include images for each page at the template level, and you can disable image output at the page level.
      The module allows you to set the priority on a per-page basis (it's optional and will not be included if not set).
      Lastly, a stylesheet option has also been added. You can use the default one (enabled by default), or set your own.
      Note that if the module is uninstalled, any saved data on a per-page basis is removed. The same thing happens for a specific page when it is deleted after having been trashed.
          
×
×
  • Create New...