Jump to content

Recommended Posts

Hi,

I'm curious if anyone has implemented some sort of template ala twig, liquid, mustache, handlebars etc. so on and so forth?

I noticed a blog post about blog themes which needed to be easier to work with than WP and using a simplified template syntax would definitely help for non-php-ers.

The requirement is that it must be as easy (or easier) than WordPress, both to install and use

Share this post


Link to post
Share on other sites

Hi. and welcome to the forum!

There's not really a point on implement something like this in Processwire. PW use of PHP is very well thought to make it easy to anyone with no PHP skills to learn and use. Have a look at this page where Ryan explains this design decision http://processwire.com/api/why-php-syntax/.

The requirement is that it must be as easy (or easier) than WordPress, both to install and use

The context of this quote is a blog ready-to-use PW install. Ryan meant that this profile should be as easy for non-programmers to start using immediately.

  • Like 2

Share this post


Link to post
Share on other sites

Hi diogo,

Thanks for the welcoming!

I forgot this topic could possibly lead to a "evangelical" debate :/

With that said, I'm glad PW has taken a stance on this one way or another. I haven't taken the time to dive into the PW templates yet so, yes, Ryan's points may very well be sound and your comment about " it easy for anyone with no PHP skills to learn and use" might also be as well.

I will say that Ryan's article touches on Smarty and to be fair that's a template engine of yesterday as far as I'm concerned unless something has changed in Smarty 3 (also debatable I'm sure.)

  • Like 2

Share this post


Link to post
Share on other sites

Not evangelical at all, as I'm not even an experienced programmer. I only learned PHP in the past few months, and I can say it was mostly because of the way PW is thought out. As a Designer I never thought I would be writing some rather advanced PHP so soon, but because PW uses PHP instead of a templating engine, and because it's designed to make it so easy for anyone to achieve basic tasks, you just feel encouraged to go further and further without any constraints.

Really, just start building a website with PW without thinking of external tools, you don't even need to install any of the excellent custom modules that are already available, and you will see how easy it is and how powerful it can get ;)

  • Like 6

Share this post


Link to post
Share on other sites

Really, just start building a website with PW without thinking of external tools, you don't even need to install any of the excellent custom modules that are already available, and you will see how easy it is and how powerful it can get ;)

I second that. Since I'm involved in another open source project which actually uses Smarty, I have been working with Smarty for some years now. I still like it because it saves me from having to do "actual" coding – Process Wire's API does just the same, but offers more flexibility and possibilities.

  • Like 1

Share this post


Link to post
Share on other sites

I was making a suggestion to make things easier for folks with less php experience and easier than WP at the same time.

This might already be the case with PW PHP syntax as it currently stands so, my suggestion maybe a bit off base.

Share this post


Link to post
Share on other sites

Nate, welcome to the forums and thanks for the suggestion. It is something that pops up every now and then and certainly something to think about. I think only thing that makes template languages more newbie friendly is that those fail silently. Forgot ending ?> from <?php and whole site won't load. This single thing might be big obstacle for someone who is just starting.

What comes to echoing variables and making simple if statements or foreach loops - I don't think that any template language is much easier than PHP. I have only used EE tags, Smarty and tried Laravel's Blade, so I don't know too much of those.

  • Like 2

Share this post


Link to post
Share on other sites

I do have an off topic yet possibly related question about PHP short tags. And excuse me if I'm being naive though, should short tags be a part of the requirements list?

Share this post


Link to post
Share on other sites

I don't think PW uses short tags internally, so using those is purely optional. I might be wrong here though...

Share this post


Link to post
Share on other sites
I don't think PW uses short tags internally, so using those is purely optional. I might be wrong here though...

Happened to have a PW site open, so I did some grepping (is that a word? should be..) and seems to me that you're absolutely right. No short tags found from core files.

@Natetronn, I'm trying to avoid getting all evangelical here, so I'm keeping this as short as possible: IMHO learning enough PHP to write templates effectively is much easier task than learning enough of most templating languages out there to do the same. PHP has very good documentation (php.net), wide user base (try googling pretty much any problem you're having and add "stackoverflow" to your query, it's rare to find a question someone hasn't already answered there) and there are many fantastic tutorials floating around. "It's easier than you think."

That said, I don't have that much experience with templating languages -- mostly I've used Twig and several in-company solutions, so I'm not much of an expert on this subject. All I can say is that after years of learning, fighting and cursing various templating languages and their shortcomings, being able to write templates in pure PHP is a bliss for me :)

  • Like 4

Share this post


Link to post
Share on other sites

Hey Teppo,

Yeah, I feel it's really a "what ever floats your boat" kind of debate or if you prefer a "left brain vs right brain" kind of thing if that makes sense?

My own experience has been that using template engines has been great though, I'm to the point where I feel they are some what of a "crutch." I mostly say that because I actually want to learn more advanced PHP (or similar language) now more then ever (before) so, my point of view has changed over time in other words.

Thanks for all the feedback by the way.

Share this post


Link to post
Share on other sites

By the way, I know my last reply probably sounded semi-hypocritical when compared to the start of this topic though, I started using template engines (smarty) back in I think 2006 give or take so, what I call a crutch now definitely helped get me get to this point and there may still be value in that all the same.

Share this post


Link to post
Share on other sites

I think only thing that makes template languages more newbie friendly is that those fail silently. Forgot ending ?> from <?php and whole site won't load. This single thing might be big obstacle for someone who is just starting.

I really don't see that much difference between

{% for item in navigation %}
  <li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endfor %}

and

<?php foreach($navigation as $item): ?>
  <li><a href="<?= $item->url ?>"><?= $item->title ?></a></li>
<?php endforeach; ?>

If you write it like this, you can forget the }} as much as the ?>

Of course the Twig code looks a little more friendly at the first sight, but the advantages of getting used to writting PHP are worth it.

Edited by diogo
  • Like 2

Share this post


Link to post
Share on other sites

Syntax is easy in both. What I meant that if you make error in php it kills the page. That is pretty extreme for live editing fellow who is just starting.

Share this post


Link to post
Share on other sites

Hm, I don't really think it's extreme. When someone decided to install the software on a server, had to mess around with permissions and so... he has to be ready to learn the hard things of life ;)

  • Like 1

Share this post


Link to post
Share on other sites

I've always thought that the "template engines make it easy for non-programmers" was a myth, as it really just comes down to semantics and what characters you think are easier to type. But the reality is that template engines give you something like a jailed environment, and that increases the comfort level of some people. The prospect of limitation becomes an asset in that context. It means it's going to be harder to break things, and there is going to be a ceiling on what can be learned. I don't ever want to be in a "jailed" environment with a low ceiling, but also kind of understand the appeal to someone that may have never stepped beyond the likes of EE (which has come crossover with our audience). As we work to broaden the audience for ProcessWire, an alternate template engine for those that desire limitation here may help us to capture new audiences. There is also just the word "PHP", which scares off some, regardless of what is real or what we do.

ProcessWire is always going to be an PHP API-driven environment at it's core, but I'm not opposed to adding on template engine(s) as an option for those that want them, in the future. It's something that's not at the top of the list on priorities, but it is something we'd like to eventually offer. They are a little more tricky to implement in PW vs. a system that is built purely for tags. The reason for this is that ProcessWire templates are executed directly by PHP rather than by ProcessWire itself. ProcessWire just hands off some API variables to the templates and lets PHP and the template execute natively. It's nice, fast and efficient. (Other systems like EE actually execute PHP code in templates using eval(); which is slow and inefficient… they hope you won't be using much PHP). The way we'd have to implement a template engine in ProcessWire, while still retaining the speed, is with compiled templates. The template using template-tags would have to be compiled to a native PHP template before it could be executed. Lots of these new template engines are designed to work that way anyway, so not a big deal, but just outlining how it would be done.

  • Like 7

Share this post


Link to post
Share on other sites

Very well said Ryan, couldn't agree more. While I know I wouldn't use template language, I think that might well make PW a little bit more beginner friendly. Not sure if it is worth the trouble (vs. writing more tutorials, getting started materials etc..).

Also maybe we could cheat a little here, and tell that PW uses templating language called "Wire", which looks like this:

Output a variable:

<?= $page->title ?>

Loop for children:

<? foreach ($page->children as $p): ?>
<h2><?= $p->title ?>
<? endforeach; ?>

;)

  • Like 6

Share this post


Link to post
Share on other sites

I like your idea of adding a "wire" template language! We can just stop referring to it as PHP and then all of the sudden people will see: wow this is a really easy template language. :)

  • Like 3

Share this post


Link to post
Share on other sites

I think that might well make PW a little bit more beginner friendly.

I think it really depends on the kind of beginner you have in mind. Someone who knows HTML farely well and maybe has some idea of programming (let's say through JS), but no PHP knowledge might actually like something like i.e. Smarty. For someone with no programming experience, but willing to learn, it might not make a difference at all.

In my experience, what "scares" people about pure PHP templating is the syntax. It's pretty close to HTML, but introduces some things they usually don't have to deal with in pure HTML like single/double quotes, special characters etc. Most template engines use a syntax which is easier to distinguish from plain HTML at first glance. That's what "comforts" them.

Bottom line, as long as it's optional, a template engine might indeed attract more users without driving away the PHP-only folks. But beware – it might as well become Pandora's box. You add one template engine, people want another one … ;)

  • Like 4

Share this post


Link to post
Share on other sites

I've used twig templates, it's pretty easy once you have the twig bits set up to just call twig to spit out templates from the normal processwire PHP pages.

I have recently started a project where I use PW purely as a CMS tool, and then have a totally seperate site (sat side by side on the same server) that uses the PW API to pull data and inject into twig templates. I have used the Silex PHP microframework, but the API is so good you could use it from any PHP code you like. If you want to use PW as a CMS and page-modelling tool and then any other set of code to actually spit out a site to the end user, it's no problem.

I'm not a fan of HTML+PHP templates, and a template language like twig is much more powerful and flexible in many ways. Inheritance of templates, sandboxed template tags, ability to create custom tags, caching, very intelligent iteration and filtering/processing to do all kinds of stuff. Not a necessity by any means (and not an insult to PW), just shows that there are many options available that can utilise the real unique power of PW (the page/data modelling and the query API) and then whatever tool you feel comfortable with to build the site.

By using Silex, we have very fine control over our site structure. The site URL structure need not mimic how the pages (or generic pieces of data as we see it) are held in the PW page tree. We are basically using PW as a data/page repository (like a big XML document full of data), then using that data in whatever way we like with the API.

If you see PW as a data-modelling tool, rather than a page-modelling tool, it opens up a whole new way of thinking about things. Each "page" in PW is really just a unit of data, it need not actually represent a page if you don't want it to.

This was typed in a rush as I head out the door, so I hope it makes sense and gives some food for thought!

  • Like 1

Share this post


Link to post
Share on other sites

Rob, very interesting. I found one of the best parts of PW is that it has strong relation to websites, ie. each page has an unique url (wheter you need it or not), nice caching, good ua control etc. So I find almost everything pw gives granted very useful and like to keep those features. But I also love the bootstrapping and using API just as a data storage, it is very flexible. I found your approach pretty radical (building whole site as bootstrapping), but very interesting and want to try it too (please do share more information, if possible). PW definitely doesn't get into your way in that method, but you get great API and admin site for free. Nice!

PS: Have to say that Twig actually looks pretty interesting.

Share this post


Link to post
Share on other sites

Apeisa - I actually agree with most of those points and even using PW as-is, without any extra flourish, it's still much easier and more flexible than 90% of other CMS I have used in 10+ years of web development, and would do fine "out of the box" for 90%+ of typical web agency situations.

Regarding the use of Silex with PW, it's really very simple. Silex is a microframework that provides a very simple mechanism for mapping regex-based URLs to a methods (actually closures, so PHP 5.3+ only), where you can stick some code. Because it is based on Symfony2, it is built to a very robust standard with best practise in mind and can make easy use of many great Symfony2 components such as Request/Response objects (HTTP handling), Twig templates, DB access with Doctrine, Session handling and many other useful bits.

In a nutshell - you map a URL to a method and in that method you use the PW API to grab data and inject into a Twig template. That's it. Your URL structures can be as simple or complex as you like with placeholders for dynamic parts e.g. canonical URL segment of blog post or the DB record ID etc (just the variable bits) and you can enforce regex rules on those parts to ensure they match a certan format.

It might seem like a lot of fuss, but it isn't really and the Twig templates are a joy. They're clean, secure, you can extend with new tags, perform all sorts of processing and iterating of data, and templates can extend each other so you can have more generic templates that get extended with specific functionality as you need it. It measn that building a slight modification of an existing template can be done very easily and in a way that doesn't have to tamper with the original at all, just like a class hierarchy in OO code.

http://silex.sensiolabs.org/

http://twig.sensiolabs.org/

I'm a bit of a Sensiolabs fanboy to be honest, and I think Fabien Potencier and the Sensiolabs team come across as being the cutting edge of PHP development. Symfony2 is a great framework, Twig is brilliant, Silex is very easy but powerful and everything they do seems to have a real sense of quality craftmanship. In combination with the excellent data modelling power (and excellent back-end interface) of Processwire, it's a good combo!

  • Like 2

Share this post


Link to post
Share on other sites

Just wanted to add to this discussion that one of the clear benefits of using templating engines is being able to share templates and partials between different programming languages, and thus between client side and server side aspects of your site. This is very handy when building web apps or heavily ajax-ified sites.

Share this post


Link to post
Share on other sites

One day we will port the "Wire" template language to javascript :)

Share this post


Link to post
Share on other sites

Didn't read all of your posts so maybe sorry if anyone else said this before but:

It isn't a huge difference if you have to learn a special wordpress template language which is much smaller then PHP or a little bit of PHP.

Like for example:

Wordpress-way:

<?php the_title(); ?>

PW-way:

<?php echo $page->title; ?>

It isn't more complicated or much longer. And also I'm loving it hove processwire handles this ;)

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 picarica
      so i am trying to fetch dimensions of image using getimagesize() but it returns nothing, at least i think so, i want to feed it to data attribute, bit its emtpy, i tried feeding it the image directly or just image->url
      here is my source code

       
      foreach($page->repeat_body as $r_body) { /* other code here*/ if ($r_body->gallery_check == 1) { echo "<div class='my-gallery' id='grid-gallery' itemscope itemtype='http://schema.org/ImageGallery'>"; foreach($r_body->image as $image) { $options = array('quality' => 80, 'upscaling' => true, 'cropping' => 'north', 'sharpening'=>'medium'); $thumb = $image->size(400, 400, $options); $large = $image->size(1280, 0, $options); list($width, $height) = getimagesize($image->url); echo " <figure itemprop='associatedMedia' itemscope itemtype='http://schema.org/ImageObject'> <a href='$large->url' itemprop='contentUrl' data-size='$widthx$height' data-index='0'> <img src='$thumb->url' height='$height' width='$width' itemprop='thumbnail' alt='Beach'> </a> </figure>"; } echo "</div>"; } /* other code here*/ } now, the images are outputted correctly, i can open then and browse them
    • By franciccio-ITALIANO
      Hello to all. I would like to create an app. So I need to learn at least one programming language. I got informed online, and discovered that javascript with node.js, is the revolution of recent years, because it's faster than php. I wonder: if I develop an app with javascript and with a javascript framework (e.g. Meteor), is there a way to integrate processwire work? I know that processwire supports the transformation of the site into an application, but would it be as simple as Meteor? With the Meteor framework I have my app online in 10 minutes, and without even knowing javascript! (Knowing javascript would serve to personalize it). I should then install the app in a SUB-DOMAIN. If I study php, instead, and if I use a php framework (e.g. Laravel), how long does it take to have my first working app? Is it easy to process Laravel's components? Is writing forms for processwire apps with php a very complex job? Is it better to use Meteor and start with javascript? What would you recommend?
    • By Chris Bennett
      Hi all, I am going round and round in circles and would greatly appreciate if anyone can point me in the right direction.
      I am sure I am doing something dumb, or missing something I should know, but don't. Story of my life 😉

      Playing round with a module and my basic problem is I want to upload an image and also use InputfieldMarkup and other Inputfields.
      Going back and forth between trying an api generated page defining Fieldgroup, Template, Fields, Page and the InputfieldWrapper method.

      InputfieldWrapper method works great for all the markup stuff, but I just can't wrap my head around what I need to do to save the image to the database.
      Can generate a Field for it (thanks to the api investigations) but not sure what I need to do to link the Inputfield to that. Tried a lot of stuff from various threads, of varying dates without luck.
      Undoubtedly not helped by me not knowing enough.

      Defining Fieldgroup etc through the api seems nice and clean and works great for the images but I can't wrap my head around how/if I can add/append/hook the InputfieldWrapper/InputfieldMarkup stuff I'd like to include on that template as well. Not even sure if it should be where it is on ___install with the Fieldtype stuff or later on . Not getting Tracy errors, just nothing seems to happen.
      If anyone has any ideas or can point me in the right direction, that would be great because at the moment I am stumbling round in the dark.
       
      public function ___install() { parent::___install(); $page = $this->pages->get('name='.self::PAGE_NAME); if (!$page->id) { // Create fieldgroup, template, fields and page // Create new fieldgroup $fmFieldgroup = new Fieldgroup(); $fmFieldgroup->name = MODULE_NAME.'-fieldgroup'; $fmFieldgroup->add($this->fields->get('title')); // needed title field $fmFieldgroup->save(); // Create new template using the fieldgroup $fmTemplate = new Template(); $fmTemplate->name = MODULE_NAME; $fmTemplate->fieldgroup = $fmFieldgroup; $fmTemplate->noSettings = 1; $fmTemplate->noChildren = 1; $fmTemplate->allowNewPages = 0; $fmTemplate->tabContent = MODULE_NAME; $fmTemplate->noChangeTemplate = 1; $fmTemplate->setIcon(ICON); $fmTemplate->save(); // Favicon source $fmField = new Field(); $fmField->type = $this->modules->get("FieldtypeImage"); $fmField->name = 'fmFavicon'; $fmField->label = 'Favicon'; $fmField->focusMode = 'off'; $fmField->gridMode = 'grid'; $fmField->extensions = 'svg png'; $fmField->columnWidth = 50; $fmField->collapsed = Inputfield::collapsedNever; $fmField->setIcon(ICON); $fmField->addTag(MODULE_NAME); $fmField->save(); $fmFieldgroup->add($fmField); // Favicon Silhouette source $fmField = new Field(); $fmField->type = $this->modules->get("FieldtypeImage"); $fmField->name = 'fmFaviconSilhouette'; $fmField->label = 'SVG Silhouette'; $fmField->notes = 'When creating a silhouette/mask svg version for Safari Pinned Tabs and Windows Tiles, we recommend setting your viewbox for 0 0 16 16, as this is what Apple requires. In many cases, the easiest way to do this in something like illustrator is a sacrificial rectangle with no fill, and no stroke at 16 x 16. This forces the desired viewbox and can then be discarded easily using something as simple as notepad. Easy is good, especially when you get the result you want without a lot of hassle.'; $fmField->focusMode = 'off'; $fmField->extensions = 'svg'; $fmField->columnWidth = 50; $fmField->collapsed = Inputfield::collapsedNever; $fmField->setIcon(ICON); $fmField->addTag(MODULE_NAME); $fmField->save(); $fmFieldgroup->add($fmField); // Create: Open Settings Tab $tabOpener = new Field(); $tabOpener->type = new FieldtypeFieldsetTabOpen(); $tabOpener->name = 'fmTab1'; $tabOpener->label = "Favicon Settings"; $tabOpener->collapsed = Inputfield::collapsedNever; $tabOpener->addTag(MODULE_NAME); $tabOpener->save(); // Create: Close Settings Tab $tabCloser = new Field(); $tabCloser->type = new FieldtypeFieldsetClose; $tabCloser->name = 'fmTab1' . FieldtypeFieldsetTabOpen::fieldsetCloseIdentifier; $tabCloser->label = "Close open tab"; $tabCloser->addTag(MODULE_NAME); $tabCloser->save(); // Create: Opens wrapper for Favicon Folder Name $filesOpener = new Field(); $filesOpener->type = new FieldtypeFieldsetOpen(); $filesOpener->name = 'fmOpenFolderName'; $filesOpener->label = 'Wrap Folder Name'; $filesOpener->class = 'inline'; $filesOpener->collapsed = Inputfield::collapsedNever; $filesOpener->addTag(MODULE_NAME); $filesOpener->save(); // Create: Close wrapper for Favicon Folder Name $filesCloser = new Field(); $filesCloser->type = new FieldtypeFieldsetClose(); $filesCloser->name = 'fmOpenFolderName' . FieldtypeFieldsetOpen::fieldsetCloseIdentifier; $filesCloser->label = "Close open fieldset"; $filesCloser->addTag(MODULE_NAME); $filesCloser->save(); // Create Favicon Folder Name $fmField = new Field(); $fmField->type = $this->modules->get("FieldtypeText"); $fmField->name = 'folderName'; $fmField->label = 'Favicon Folder:'; $fmField->description = $this->config->urls->files; $fmField->placeholder = 'Destination Folder for your generated favicons, webmanifest and browserconfig'; $fmField->columnWidth = 100; $fmField->collapsed = Inputfield::collapsedNever; $fmField->setIcon('folder'); $fmField->addTag(MODULE_NAME); $fmField->save(); $fmFieldgroup->add($tabOpener); $fmFieldgroup->add($filesOpener); $fmFieldgroup->add($fmField); $fmFieldgroup->add($filesCloser); $fmFieldgroup->add($tabCloser); $fmFieldgroup->save(); /////////////////////////////////////////////////////////////// // Experimental Markup Tests $wrapperFaviconMagic = new InputfieldWrapper(); $wrapperFaviconMagic->attr('id','faviconMagicWrapper'); $wrapperFaviconMagic->attr('title',$this->_('Favicon Magic')); // field show info what $field = $this->modules->get('InputfieldMarkup'); $field->name = 'use'; $field->label = __('How do I use it?'); $field->collapsed = Inputfield::collapsedNever; $field->icon('info'); $field->attr('value', 'Does this even begin to vaguely work?'); $field->columnWidth = 50; $wrapperFaviconMagic->add($field); $fmTemplate->fields->add($wrapperFaviconMagic); $fmTemplate->fields->save(); ///////////////////////////////////////////////////////////// // Create page $page = $this->wire( new Page() ); $page->template = MODULE_NAME; $page->parent = $this->wire('pages')->get('/'); $page->addStatus(Page::statusHidden); $page->title = 'Favicons'; $page->name = self::PAGE_NAME; $page->process = $this; $page->save(); } }  
    • By benbyf
      Hello, and welcome to what I though was either my client being silly and changing things, or some evil doer. Turns out its reproducible and therefore something in Proceswire (I checked my templates and modules but couldnt find anything that would be doing this...). So what is it doing? Check out the video for evidence.
      A repeater field is interacting with a page template and another repeater field somehow to swap the fields in the template and repeater over...
      I have a template called team, and a repeater field called team_repeater with label Team. Some how and for some reason, when I change my fields on repeater called main_menu_links my team template gets those fields and when I try and revert the team template fields to the fields it should have, they get given to the repeater main_menu_links. Also this to say HELP!!!!!
      video: https://www.dropbox.com/s/exkdhc6n7x0xpsa/strange-repeater-PW-mega-bug.mov?dl=0
    • By Aleksey Popov
      Hi! Is it possible to specify explicitly the parent section when creating a new child page with a single template?
      The idea is to save the user from the possibility of mistakenly choosing a section, but not to create unnecessary identical templates
      What I mean:
      Let's say I've got 2 parent categories with names articles & news. Each of them utilized the same admin-template (category) with the category.php file. Also, I have 2 different templates for child pages (article & news).
      Next, I need to add an article page to the articles category with the "create new" button in admin. At that moment, I must choose the category to place (because both categories use the same template). 
      To runaround this (and create a page right into the exact category without the choosing step) I should create 2 templates for each category, and setup parent-children relations for each pair of templates, right?
      But Is any way to use only the one category template and different children templates and at the same time, explicitly specify which section to use for child pages, thereby removing the process of selecting a child section?
       
      articles (category.php) Article page 1 (page-article.php) Article page 2 (page-article.php) Article page 3 (page-article.php) + Add a new article page here without category chooser news (category.php) News page 1 (page-news.php) News page 2 (page-news.php) News page 3 (page-news.php)  Update: found module  but I can't get it work.
       
×
×
  • Create New...