Jump to content
tpr

Module: Template Latte Replace

Recommended Posts

2 minutes ago, Nicolas said:

Hi,

Has anyone succeeded running Hanna Code with Latte template. I'm strugling getting them to work together. Is there  a setting to prevent latte to process Hanna Code tags ?

Thanks.

I haven't tried, but maybe changing the Open and Close tag settings in the Hanna code config might help you get around it:

Admin > Modules > Hanna Code Text Formatter

Share this post


Link to post
Share on other sites

@adrian Already tried that but whatever the open and close tag choosen, Latte template will try to load the file with the name of the code. For example i have a Hanna code named "quote". Then i've got the following this error : Error: Exception: Missing template file '/Volumes/DATA/www/ceea/site/templates/views/quote.latte'

Share this post


Link to post
Share on other sites

Could you share your current code? I haven't used it in .latte files, only in CKEditor.

Share this post


Link to post
Share on other sites

In the latte file i've got the following code

<div class="entry-main">
  <h3 class="entry-title ui-title-inner">{$page->title|noescape}</h3>
  <div class="entry-content">
    {$page->body|noescape}
  </div>
</div>

The body field is configured to process Hanna Code as a text formatter

Share this post


Link to post
Share on other sites

It is interesting because this is the way I use it and no issues here. What is your Latte module version and the open-close tags for Hanna?  Do you have other textformatters applied to body? I have Video Embed for Youtube/Vimeo and they work fine together.

Share this post


Link to post
Share on other sites

The body field is a CKEditor field to which the Hana code text formatter is being applied.

The version of the TeplateLatteReplace is 0.2.0

Share this post


Link to post
Share on other sites

I could duplicate the issue, it happens if your Hanna code type is set to PHP. I will try to find a fix or a workaround.

Share this post


Link to post
Share on other sites

Success! Try upgrading to version 021.

  • Like 1

Share this post


Link to post
Share on other sites

I really like this module and the ease of the Latte syntax, but when trying to start my first project (both in Latte & PW) I found the following questions:

  1. Where implement the business logic for the @layout file? if this file is only for output and its not a good practice to include php logic. For example I need to do some processing before printing the site header and the area for the logged user.
  2. Following the previous question, if the option for including Blocks require a more complex data process, where I do that? I have no controller file for Blocks/Chunks and only can pass variables directly inside the Latte view that include it
  3. The multi-language native processwire system does not work, for example the url "sitename.com/es/" causes an include error.

I want to implement my sites using Latte, but now I'm worried if it suits the complexities that can appear during dev

Share this post


Link to post
Share on other sites

Hi,

perhaps Latte is not the best choice for beginners in PW but I guess you have some programming background judging from your questions :)

1. You can use ready.php for example for such purposes (or init.php, _init.php, perhaps _main.php). Or you can add two blocks to the layout, one for the site header and one for the logged in user. You can leave the block you don't need empty and it won't be rendered. I sometimes use PHP logic in my view files but it's rather because my lazyness :)

2. Well you do your logic in {template}.php and set variables to output in {template}.latte. You can use another .latte file in {template}.php, so eg. you can include login.latte or register.latte if you need that. You can even render a chunk in the php (controller) file to a variable and use in the final view file.

3. Could you provide more details? I've done all my PW multilanguage sites with Latte and haven't encountered such an error.

I think Latte is just as good as Twig or others, maybe a bit more forgivable in some cases. So I think the question for you is perhaps to use a template engine or not.

  • Like 2

Share this post


Link to post
Share on other sites

Here are two macros that I started to use recently to avoid passing full page objects and make things easier.

I usually set "common" pages in ready.php like this:

// Pages
$view->homepage = $pages->get(1);
$view->contactPage = $pages->get(1033);
// PageArrays
$view->menuItems = $pages->find('id=1010|1020|1030,sort=sort');

But instead of this I set only ID (selector):

// Pages
$view->homepage = 1
$view->contactPage = 1033;
// PageArrays
$view->menuItems = 'id=1010|1020|1030,sort=sort';

Now in latte template files I use the macro "n:page" or "n:pages", which automatically sets the "$p" variable ("$pArr" in case of n:pages).

Basically it sets the context:

<a n:page="$contactPage" class="contact" href="{$p->url}">{$p->title}</a>
<ul n:pages="$menuItems" n:inner-foreach="$pArr as $p">
    <li class="{$p|activeClass|noescape}">
        <a href="{$p->url}">{$p->title|noescape}</a>
    </li>
</ul>

You can use this if you prefer "normal" macros instead "n:macros":

{page $contactPage}
    <p>{$p->httpUrl}</p>
{/page}

And here are the macros (put it in site/ready.php):

$view->_addMacro['page'] = array(
    'page',
    '$p = \ProcessWire\wire("pages")->get(%node.word)',
    ';'
);

$view->_addMacro['pages'] = array(
    'pages',
    '$pArr = \ProcessWire\wire("pages")->find(%node.word)',
    ';'
);

 

  • Like 4

Share this post


Link to post
Share on other sites

Looks like there was a bug in the module, allowing only one macro to be added. I've pushed a fix for this (v022).

Share this post


Link to post
Share on other sites

Another tip today: a filter to easily get pages in templates :)

Usage:

// homepage url (1: page ID)
<a href="{(1|getPage)->url}" class="logo">

// custom selector
<a href="{('name=about'|getPage)->url}" class="logo">

Filter (add to ready.php):

$view->_filters['getPage'] = function ($selector) {
    return isset($selector) ? wire('pages')->get($selector) : false;
};

I wouldn't recommend to use it with selectors but it's there if needed. It's better to use with variables set in template php files.

  • Like 1

Share this post


Link to post
Share on other sites

I have some PW installations with the "ready.php" file in the site root and others not, Why? For example "Default" profile have it, but "Multi-language" not. It's best practice using it?

Share this post


Link to post
Share on other sites

It's fine to use it or not. If a profile doesn't have it, just create it and use as your needs dictate.

  • Like 1

Share this post


Link to post
Share on other sites

So, if I need to use the "init", "ready" or "finished" files in my project, I put them in the site root. But, I need to configure PW to include them in the process?

Share this post


Link to post
Share on other sites
1 minute ago, Pixrael said:

But, I need to configure PW to include them in the process?

Nope, if they exist they will be processed.

  • Like 1

Share this post


Link to post
Share on other sites

OK, so easy as usual in PW!! Thanks
Note: Maybe this question is out of the scope for this entries, so if you want to move it to another topic is okay.

  • Like 1

Share this post


Link to post
Share on other sites

v2.4 is up:

  • added additional filters and macros (optional, see README)
  • added 'languages', 'fields', 'templates', 'logs' to the default API variables (suggested by Pixrael)
  • remove cache directory on uninstall

 

  • Like 2

Share this post


Link to post
Share on other sites

About the API variables: It seems perfect because in any medium projects you need almost all those variables, then from factory you have all the infrastructure ready to work. If you need something from the PW API it's there, it's much better for newbies. If you are a fan of optimizations (you are supposed to be a smart programmer) you can go to the module source and remove it, or whatever you want to do with it.

Share this post


Link to post
Share on other sites

I was about to make (some) fuels optional but haven't noticed performance issues having all enabled. Editing the module is not a smart option, I can add a hook instead to modify the fuels to be loaded, if there's a need.

Share this post


Link to post
Share on other sites

The new v025 has a new feature "Use latte extension" that allows replacing PHP templates with Latte files, resulting in a cleaner structure. Note that /site/templates/admin.php needs to be renamed to admin.latte when using this. On existing installations it is recommended to clear the cache too.

  • Like 1

Share this post


Link to post
Share on other sites

v026 brings another "syntactic sugar" because the sweeter the better :)

{1038|get:httpUrl}
{$contactPage|get:title}
{$gallery_items|getParent|get:httpUrl}

 

  • Like 2

Share this post


Link to post
Share on other sites

v027 contains some code improvements. There are two new filters, "count" and "breadcrumb". The latter is a bit different from the rest because it generates markup but it has many options to fine-tune. Currently it doesn't generate any separators between the items, I think it's better to do with CSS but let me know if you think otherwise.

  • root: root page to start the breadcrumb from (selector or Page). Default: Home page
  • addHome: whether to prepend the Home page. Default: true
  • addCurrent: append the current page. Default: false
  • addCurrentLink: whether to add link when appending the current page. Default: false
  • class: CSS class to add to the "ul" tag. Default: "breadcrumb". Pass an empty string to remove class.
  • id: CSS id to add to the "ul" tag. Default: none (no id added)
  • addAttributes: add "data-page" attributes to 'LI' tags with the corresponding page id. Default: false
{$page|breadcrumb|noescape}
{$page|breadcrumb:array('addCurrent' => true, 'addHome' => false, 'addCurrentLink' => true)|noescape}
  • 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 Robin S
      A community member raised a question and I thought a new sanitizer method for the purpose would be useful, hence...
      Sanitizer Transliterate
      Adds a transliterate method to $sanitizer that performs character replacements as defined in the module config. The default character replacements are based on the defaults from InputfieldPageName, but with uppercase characters included too.
      Usage
      Install the Sanitizer Transliterate module.
      Customise the character replacements in the module config as needed.
      Use the sanitizer on strings like so:
      $transliterated_string = $sanitizer->transliterate($string);
       
      https://github.com/Toutouwai/SanitizerTransliterate
      https://modules.processwire.com/modules/sanitizer-transliterate/
       
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version to 2.10, add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By thomasaull
      I created a little helper module to trigger a CI pipeline when your website has been changed. It's quite simple and works like this: As soon as you save a page the module sets a Boolean via a pages save after hook. Once a day via LazyCron the module checks if the Boolean is set and sends a POST Request to a configurable Webhook URL.
      Some ideas to extend this:
      make request type configurable (GET, POST) make the module trigger at a specified time (probably only possible with a server cronjob) trigger manually Anything else? If there's interest, I might put in some more functionality. Let me know what you're interested in. Until then, maybe it is useful for a couple of people 🙂
      Github Repo: https://github.com/thomasaull/CiTrigger
    • By Robin S
      I created this module a while ago and never got around to publicising it, but it has been outed in the latest PW Weekly so here goes the support thread...
      Unique Image Variations
      Ensures that all ImageSizer options and focus settings affect image variation filenames.

      Background
      When using methods that produce image variations such as Pageimage::size(), ProcessWire includes some of the ImageSizer settings (height, width, cropping location, etc) in the variation filename. This is useful so that if you change these settings in your size() call a new variation is generated and you see this variation on the front-end.
      However, ProcessWire does not include several of the other ImageSizer settings in the variation filename:
      upscaling cropping, when set to false or a blank string interlace sharpening quality hidpi quality focus (whether any saved focus area for an image should affect cropping) focus data (the top/left/zoom data for the focus area) This means that if you change any of these settings, either in $config->imageSizerOptions or in an $options array passed to a method like size(), and you already have variations at the requested size/crop, then ProcessWire will not create new variations and will continue to serve the old variations. In other words you won't see the effect of your changed ImageSizer options on the front-end until you delete the old variations.
      Features
      The Unique Image Variations module ensures that any changes to ImageSizer options and any changes to the focus area made in Page Edit are reflected in the variation filename, so new variations will always be generated and displayed on the front-end.
      Installation
      Install the Unique Image Variations module.
      In the module config, set the ImageSizer options that you want to include in image variation filenames.
      Warnings
      Installing the module (and keeping one or more of the options selected in the module config) will cause all existing image variations to be regenerated the next time they are requested. If you have an existing website with a large number of images you may not want the performance impact of that. The module is perhaps best suited to new sites where image variations have not yet been generated.
      Similarly, if you change the module config settings on an existing site then all image variations will be regenerated the next time they are requested.
      If you think you might want to change an ImageSizer option in the future (I'm thinking here primarily of options such as interlace that are typically set in $config->imageSizerOptions) and would not want that change to cause existing image variations to be regenerated then best to not include that option in the module config after you first install the module.
       
      https://github.com/Toutouwai/UniqueImageVariations
      https://modules.processwire.com/modules/unique-image-variations/
    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      ProcessWire-Module: http://modules.processwire.com/modules/page-access-releasetime/
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
×
×
  • Create New...