Adding your first Live Template

Posted by gerdami on 15 Feb 2009 10:36, last edited by leiger on 19 Mar 2013 03:15

Tags: template

rating: +4+x

You have created you first pages, congratulations!

You already know how to group your pages in a category, let's say the category is blog:

blog:page1 looks like

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce orci ligula, vehicula vel, iaculis vitae, adipiscing sed, urna. Aenean egestas urna nec felis. Etiam augue turpis, varius vitae, luctus iaculis, commodo viverra, erat. Praesent eleifend tincidunt odio. Sed ullamcorper nulla id odio. Morbi facilisis nisi vitae est. Nunc in urna sodales augue convallis aliquet. In nec velit et nulla tristique consectetur. Aliquam ante. Vivamus aliquam velit et risus. Fusce luctus velit a sapien. Nullam ultricies ullamcorper dolor. Maecenas id risus a tellus interdum consectetur. Quisque consectetur, urna in malesuada venenatis, enim massa gravida ligula, non tempus arcu libero eu urna. Nunc scelerisque, magna at aliquam accumsan, sem ligula bibendum sapien, sed iaculis magna nunc at elit. Curabitur et pede. Integer a eros. Nunc vehicula tellus sed lorem.

blog:page2 looks like

Etiam consequat libero faucibus lacus. Donec molestie, velit vel semper pretium, dui mi scelerisque mi, a ultricies mauris justo vitae urna. Curabitur suscipit, pede eu porta volutpat, lorem turpis venenatis mi, vel pretium enim turpis quis risus. Vivamus lorem. Praesent nulla sapien, tincidunt eget, viverra eget, condimentum ac, magna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras purus ligula, laoreet sed, vestibulum eleifend, rhoncus eget, velit. Integer nec nulla. Mauris ornare purus scelerisque augue. Proin bibendum. Aenean adipiscing, risus in facilisis cursus, erat leo porttitor velit, ut fringilla odio nunc nec turpis. Sed nisl turpis, rhoncus ut, consectetur sit amet, ornare non, nisl. Nullam aliquam, erat nec suscipit lacinia, ipsum dui luctus est, adipiscing blandit lacus augue sed sem. Mauris vitae lorem. Donec ac dolor. Phasellus fermentum ornare ligula.

Of course you have now many pages in your category blog:
But you're not happy. You would like your visitors to be able to comment on your blog:pages by adding the [[module Comments]] below the text.
Does this mean you have to edit all existing pages and append the [[module Comments]]?
NO.

Apply a _template

You just need to apply a live _template to category blog: by creating the page blog:_template with the following content:

%%content%%

+++ Discuss
[[module Comments title="" hide="false" hideForm="false"]]

The %%content%% is the whole content of your blog:pages. When you save the blog:_template page, all existing blog:pages are recompiled and the module Comments will be appended to existing pages. New blog:pages will have also the same layout.
Warning: if you create the "_template" in a new page button field and NOT in the adressbar (URL) of the browser - than the "leading underscore" will be removed! You can than "rename" the page imn the "+options buttons" to a name with the leading underscore… or:
You have to create ( at the moment) such pages in the adressbar ( url ) !

Hence, blog:page1 will now look like

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce orci ligula, vehicula vel, iaculis vitae, adipiscing sed, urna. Aenean egestas urna nec felis. Etiam augue turpis, varius vitae, luctus iaculis, commodo viverra, erat. Praesent eleifend tincidunt odio. Sed ullamcorper nulla id odio. Morbi facilisis nisi vitae est. Nunc in urna sodales augue convallis aliquet. In nec velit et nulla tristique consectetur. Aliquam ante. Vivamus aliquam velit et risus. Fusce luctus velit a sapien. Nullam ultricies ullamcorper dolor. Maecenas id risus a tellus interdum consectetur. Quisque consectetur, urna in malesuada venenatis, enim massa gravida ligula, non tempus arcu libero eu urna. Nunc scelerisque, magna at aliquam accumsan, sem ligula bibendum sapien, sed iaculis magna nunc at elit. Curabitur et pede. Integer a eros. Nunc vehicula tellus sed lorem.

Discuss
show comments

A good idea would be to prepend the blog:pages by the Author's name and date of post.
Edit the blog:_template again:

Posted by %%author%% on %%date%%

%%content%%

+++ Discuss
[[module Comments title="" hide="false" hideForm="false"]]

Hence, blog:page1 will now look like

Posted by [icon] gerdami on 14 Dec 2008, 18:47 +0100

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce orci ligula, vehicula vel, iaculis vitae, adipiscing sed, urna. Aenean egestas urna nec felis. Etiam augue turpis, varius vitae, luctus iaculis, commodo viverra, erat. Praesent eleifend tincidunt odio. Sed ullamcorper nulla id odio. Morbi facilisis nisi vitae est. Nunc in urna sodales augue convallis aliquet. In nec velit et nulla tristique consectetur. Aliquam ante. Vivamus aliquam velit et risus. Fusce luctus velit a sapien. Nullam ultricies ullamcorper dolor. Maecenas id risus a tellus interdum consectetur. Quisque consectetur, urna in malesuada venenatis, enim massa gravida ligula, non tempus arcu libero eu urna. Nunc scelerisque, magna at aliquam accumsan, sem ligula bibendum sapien, sed iaculis magna nunc at elit. Curabitur et pede. Integer a eros. Nunc vehicula tellus sed lorem.

Discuss
show comments

Summary

You discovered in this howto that you can change the layout of existing pages by applying a _template to a category of pages. Now you know that the content of page is a variable %%content%%. The author's name and creation date are rendered by the variables %%author%% and %%date%%.

If you have a look at the documentation on live _templates, you will learn that a page can be divided in several content parts which will be used as %%content{1}%%, %%content{2}%%, etc. and that you can use much more variables. Happy discovery!

Related

Author

gerdamigerdami. Please visit his/her userPage.


Related articles

Comments

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.