Jump to content
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

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 cboetens
      Hi guys
      I guess this is the right forum to post my question. If not, do let me know. Ok, I'm fairly new to ProcessWire and so far I really like the CMS! It's magnificent to use and really straight forward. Big thanks to Ryan for that.
      Now, the question I have. I have a template called 'products_categories.php' in which I collect and render all the different categories (the categories basically act as a filter) for a variety of products and next to the categories, I render all the products, like so:
      <?php include('includes/header.php') ?> <?php $categoryName = $sanitizer->pageName($input->urlSegment(1)); $subcategoryName = $sanitizer->pageName($input->urlSegment(2)); pre($categoryName); pre($subcategoryName); $categories = $page->get("template=products_categories"); $category = $categories->get("template=products_categories_item, name=" . $categoryName); if($category->id){ $session->category = $category->id; $subcategory = $category->get("template=products_categories_item, name=" . $subcategoryName); if($subcategory->id){ $session->subcategory = $subcategory->id; } } $selector = "template=products_item"; if($category->id){ $selector .= ", products_categories=" . $category; } if(isset($subcategory->id)){ $selector .= ", products_categories=" . $subcategory; } $products_items = $page->find($selector); ?> <div class="uk-section"> <div class="uk-container"> <?php if(!empty($page->headline)) { ?> <h1><?= $page->headline ?></h1> <?php } ?> <!-- **** COMMENT: create grid for products **** ---> <div class="row"> <div class="col-md-3"> <div class="uk-card mr-3 uk-card-default uk-card-body"> <h3 class="uk-card-title">Productcategorieën</h3> <ul class="uk-list"> <?php foreach($categories->children() as $c){ ?> <li class="<?= ($category->id===$c->id ? 'active ' : '') ?>"> <a href="<?= $page->url . $c->name . '/' ?>"><?= $c->title; ?></a> <?php if($c->hasChildren){ ?> <ul> <?php foreach($c->children() as $sc) {?> <li class="<?= ($category->id==$c->id && $subcategory->id==$sc->id ? 'active ' : '') ?>"> <a href="<?= $page->url . $c->name . '/' . $sc->name . '/' ?>"><?= $sc->title; ?></a> </li> <?php } ?> </ul> <?php } ?> </li> <?php } ?> </ul> </div> </div> <div class="col-md-9"> <div class="uk-child-width-1-3@s uk-grid-match uk-grid-margin-small uk-grid-small" uk-grid> <?php foreach($products_items as $product) { ?> <div class="uk-card"> <?php if(isset($product->image)) { ?> <div class="uk-card-media-top"> <img src="<?= $product->image->URL; ?>" title="<?= $product->title; ?>" alt="<?= $product->intro; ?>"> </div> <?php } ?> <?php if(!empty($product->title) || !empty($product->intro)) { ?> <div class="uk-card-body uk-card-default"> <?php if(!empty($product->title)) { ?> <h3 class="uk-card-title"><?= $product->title; ?></h3> <?php } ?> <?php if(!empty($product->intro)) { ?> <p><?= $product->intro; ?></p> <?php } ?> <?php if (!empty($product->price)): ?> <h3 class="uk-card-title">&euro;&nbsp;<?= $product->price; ?>&nbsp;(excl. btw)</h3> <?php endif; ?> <a class="uk-button uk-button-primary" href="<?= $product->url; ?>">Bekijk</a> </div> <?php } ?> </div> <?php } ?> </div> </div> </div> </div> </div> <?php include('includes/footer.php'); ?> Now, I can't seem to get the filter to work. The URL behind every (sub)category should go straight back to the template 'products_categories.php', that way I can get a range of products according to the selected/ clicked URL.
      What am I missing here? Is this not the correct way to handle things?
      Any help is welcome!
      Thanks.
      Cédric
    • By DooM
      Hello,
      I'm working on something like "structure generator" for my own needs which is run after clean installation of PW to create basic structure, fields, install modules, remove unnecessities, etc.
      I'm trying to remove site/templates/scripts and site/templates/styles folders, but I'm out of ideas already. When I try PHP's unlink function, it says that the path doesn't exists, which is obvious, because it will try to delete those folders under FileCompiler folder. This is probably because PW compilation process? I'm initializing this mine "structure generator" in ready.php.
      Do any of you guys have any idea how to get rid of those folders? My styles and scripts folders are separated, so I don't need those two inside templates folder.
      Thanks for every advice. 🙂
    • By MateThemes
      Hello everyone!
      I am trying to add my repeater matrix fields to the search selector, but unfortunately nothing seems to work for me.
      I have following search code in my search.php:
      <?php namespace ProcessWire; // look for a GET variable named 'q' and sanitize it $q = input()->get('q'); // sanitize to text, which removes markup, newlines, too long, etc. $q = sanitizer()->text($q); // did $q have anything in it after sanitizing to text? if($q) { // Make the search query appear in the top-right search box. // Always entity encode any user input that also gets output echo '<input id="search-query" value="' . sanitizer()->entities($q) . '">'; // Sanitize for placement within a selector string. This is important for any // values that you plan to bundle in a selector string like we are doing here. // It quotes them when necessary, and removes characters that might cause issues. $q = sanitizer()->selectorValue($q); // Search the title and body fields for our query text. // Limit the results to 50 pages. The has_parent!=2 excludes irrelevant admin // pages from the search, for when an admin user performs a search. $selector = "title|body~=$q, limit=50, has_parent!=2"; // Find pages that match the selector $matches = pages()->find($selector); } else { $matches = array(); } // unset the variable that we no longer need, since it can contain user input unset($q); ?> <main pw-replace='main'> <?php include('./includes/_pageheadersearch.php'); ?> <div id='content-body' class='uk-section uk-section-large uk-section-large'> <div class='uk-container uk-container-small'> <?php // did we find any matches? if(count($matches)) { // yes we did, render them echo ukAlert(sprintf(_n('Found %d page', 'Found %d pages', $matches->count), $matches->count), "default", "check"); echo ukDescriptionListPages($matches); } else { // we didn't find any echo ukAlert(__('Sorry, no results were found'), "danger", "warning"); } ?> </div> </div> </main> I have tried to add my fields to the selector code (repeater_matrix.aboutsblock_repeaters.mytextfield) . But I didn't get any results.
      What I am doing wrong?
      Thanks for your help!
    • 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.
×
×
  • Create New...