EyeDentify

Confused about Markup Regions in PW? Read this!

Recommended Posts

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 

  • Like 2

Share this post


Link to post
Share on other sites

I'm actually more confused about an apparently new (to me) way to use the API... I've never seen code writen like this before:

$home = pages()->get('/'); // instead of $home = $pages->get('/');

I see in the config file 

$config->useFunctionsAPI = true; 

Is that the reason? Do you happen to know when this was introduced or announced? Can it do certain stuff faster/better or different than the old-school PW API syntax?

Share this post


Link to post
Share on other sites
25 minutes ago, dragan said:

my bad, of course searching before posting would have been more clever - I found it:

https://processwire.com/blog/posts/processwire-3.0.39-core-updates/#new-functions-api

 

No Worries. Indeed its a fairly new API.

You can also check it out in the source code at:
https://github.com/processwire/processwire/blob/master/wire/core/FunctionsAPI.php

For more details. Hope you find it useful.

Cheers.

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 Robin S
      This module corrects a few things that I find awkward about the "Add New Template" workflow in the PW admin. I opened a wishlist topic a while back because it would good to resolve some of these things in the core, but this module is a stopgap for now.
      Originally I was going to share these as a few standalone hooks, but decided to bundle them together in a configurable module instead.
      Add Template Enhancements
      A module for ProcessWire CMS/CMF. Adds some efficiency enhancements when adding or cloning templates via admin.

      Features
      Derive label from name when new template added: if you like to give each of your templates a label then this feature can save some time. The label can be added automatically when templates are added in admin, in admin/API, or not at all. There are options for underscore/hyphen replacement and capitalisation of the label. Edit template after add: when adding only a single template, the template is automatically opened for editing after it is added. Copy field contexts when cloning: this copies the field contexts (a.k.a. overrides such as column width, label and description) from the source template to the new template when using the "Duplicate/clone this template?" feature on the Advanced tab. Copy field contexts when duplicating fields: this copies the field contexts if you select the "Duplicate fields used by another template" option when adding a new template. Usage
      Install the Add Template Enhancements module.
      Configure the module settings according to what suits you.
       
      https://github.com/Toutouwai/AddTemplateEnhancements
      https://modules.processwire.com/modules/add-template-enhancements/
    • By joe_ma
      On a new pw 3.0.89 installation of mine I've got a problem with role permissions. The setup is like this:
      Templates: home, basic-page, text-only, folder
      All of these have no restrictions in the "family" section and all of them have the same access definitions (see edit-template.jpg below)
      There is a role "redaktor" that has permission to edit, add, delete, move and also clone pages (see permissions.jpg below).
      Now, when logged in as a user with this role, I can only choose from basic-page and folder. The text-only template is not available.


    • 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
      Hello Fellow PW Fans and Gurus.

      I have run into a problem where i have created a template without a template file associated with it.
      Now i would like to HAVE a template file associated with it, not an alternate but as the main template file.

      So i thought, that's easy, I upload the template file and change it in template settings but I only get the Alternate template file setting?

      Ok so maybe i can change it via the API , so i wrote some code for this.
      <?PHP function changeTemplate($pages = null, $templates = null) { /* get the pages to change template on */ $logItems = $pages->findMany('template=tmp_log_item'); /* get the template object for our desired template */ $Template = $templates->get('tmp_new_log_item'); foreach($logItems AS $key => $logData) { /* use template object $Template to set template */ $logData->template = $Template; /* save page item */ $logData->save(); } } /* do the magic change */ changeTemplate(); ?> Needless to say, PW was not happy about this, It throw up an error message:
      Error: Exception: Invalid value sent to Page::setTemplate (in /home/virtual/mydomain/public_html/wire/core/Page.php line 1782)
      Now from what i understand i gave $logData->template the wrong type of value.
      So what should the value be to correct this?
      When I read the docs at: https://processwire.com/api/ref/page/
      the value can be "string" or "Template".

      So i gave it a string and it went haywire.

      How should I approach this cause I realy dont want to manually change template file on över 50 plus pages

      Maybe I should use the Template class to create the value that the API wanted, but I am unsure how to use it.

      Thank you for any info you can give me on this.

      If you want more info to help me, ask and I will try my best to give it to you.
      Updated and Solved
      I solved the problem and have updated the code to reflect this.

      Essentialy i used the get() method of $templates to get the template object for my template i wanted to use using the template name.
      I gave the Object to the $logData->template property and all went well.
      We learn something new every day.
      One Note:
      The template file you want to use must have been uploaded and added as a template in the Template section in the Admin for this code to work as expected.
    • By louisstephens
      So I am making a front-end dashboard for an internal project, and was curious if it is possible to match 2 pages together based on their title and retrieve the data.
      To make it more clear:
      I have two pages "Section A"  and "Section B" that each has child pages with names (the specific person) with subpages for their services offered. 
      Section A - John Doe (name=john-doe) - Service 1 - Service 2 - Service 3 - Jane Doe (name=jane-doe) - Service 1 - Service 2 - Service 3 Section B - John Doe (name=john-doe) - Service 4 - Service 5 - Service 6 - Jane Doe (name=jane-doe) - Service 4 - Service 5 - Service 6 What I would like to achieve on the front-end (if it is even possibile), is an output like:
      John Doe - Service 1 - Service 2 - Service 3 - Service 4 - Service 5 - Service 6 Jane Doe - Service 1 - Service 2 - Service 3 - Service 4 - Service 5 - Service 6 Thinking aloud: use a find to get all pages using the template "service user" and then foreaching through their children (and possibly getting a few field values as well) to output in the front end. The service templates used in the sections vary slightly in which fields they use.
      <?php $findUsers = $pages->find("template=service-a (and or) service-b,(some how match based on names)"); //if no match exists, output what is available ?> <ul> <?php foreach ($findUsers as $groupedUser): ?> <li><?php echo $groupedUser->title; ?></li> <li><?php echo $groupedUser->service_a_location; ?></li> <li><?php echo $groupedUser->service_a_body; ?></li> <li><?php echo $groupedUser->service_b_location; ?></li> <li><?php echo $groupedUser->service_b_phone; ?></li> <?php endforeach; ?> </ul> Sorry, it is just me thinking aloud, but I was not even sure if it is possible to group them together like that. I was going to have a page for each "section" only displaying that data, but I thought it would be nice to display them all together as an overview for the user.