The power of Template Inheritance and the CMSMS Design Manager
Previous article Next articleTemplate Inheritance is an approach to managing Smarty templates in CMS Made Simple™ that resembles object-oriented programming techniques. It was introduced in Smarty 3 and for us in CMSMS™ 1.11.
Instead of the traditional use of Global Content Blocks (GCB's) or {include ...} tags to manage parts of templates, you can inherit the contents of one template to another and change blocks of content therein. This keeps template management minimal and efficient, since each template only contains the differences from the template it extends. Also template inheritance allows reducing the number of 'if' statements in a template, conditional layouts can be changed to be placed in different derived templates. Read more at http://www.smarty.net/inheritance.
How to use
As an example, we want to create a website with different page lay-outs like I have here at my blog:
- A default page with one column of content,
- a page with two columns
- and a page with three columns.
Using Template Inheritance there is no need for Global Content Blocks (GCB's) or including subtemplates in the main Core::Page template!
1. Create a new design
Open in the CMSMS Admin panel the Design Manager module, therefor you go to Layout >> Design Manager.
In the Options dropdown select Create a new Design, enter the design name and click on Submit.
2. Create and attach Stylesheets
Open in the Design Manager the tab Stylesheets and select in the dropdown Create a new Stylesheet. Fill in a name and add your styling content. In the tab Design we attach the stylesheet to the design we created above! Do this for all stylesheets you need.
This is one of the nice features of the Design Manager module, before you needed to attach the stylesheet to each template. Now only once to the Design!
Note: In this tutorial I describe the Template Inheritance method, not the styling of the (responsive) block layout. Perhaps in another tutorial...
3. Create Core::Page templates
We start with building a base Core::Page template: the simplest lay-out with just one column.
In the Design Manager you open the tab Templates where we create a new Core::Page template.
Set in the Advanced tab Listable to No, so it won't show up in the template selector in Content Manager.
Certain parts of the template we put within {block} and {/block} Smarty tags and give them unique names.
- In the template top the default content block,
- the main content area
- and - as an example - an empty spot where we can later add jQuery code if we need it in a certain template.
Base Page Template
{process_pagedata}
{block name='top'}
{$content = "{content}" scope=global}
{/block}
{/strip}<!DOCTYPE HTML>
<html lang="en">
<head>
{metadata}
{cms_stylesheet}
</head>
<body>
<header>
<div class="c_full">
<div class="grid_12"><h1>CMS Made Simple</h1></div>
</div>
</header>
<nav>
<div class="c_full">
<div class="grid_12">{Navigator}</div>
</div>
</nav>
<main>
{block name='content'}
<div class="c_full">
<div class="grid_12">{$content}</div>
</div>
{/block}
</main>
<footer>
<p>This website is proudly powered by CMS Made Simple - Copyright {custom_copyright}</p>
</footer>
</body>
{block name='jquery'}{/block}
<script>
// Matomo/Piwik - Google Analytics code
</script>
</html>
4. Create the Templates
Template: One Column
Now we have the base Core::Page template ready, we can create a template for one column:
The base Core::Page template is included and we don't make any changes or additions...
Template: Two Columns
Again the base Core::Page template is included, but we now add a second content block. The result, we have a template with two columns:
{block name='top' append}
{$content2 = "{content block='content2'}" scope=global}
{/block}
{block name='content'}
<div class="c_full">
<div class="grid_6">{$content}</div>
<div class="grid_6">{$content2}</div>
</div>
{/block}
Template: Three Columns
Here we add two extra content blocks and have a template for three columns:
{block name='top' append}
{$content2 = "{content block='content2'}" scope=global}
{$content3 = "{content block='content3'}" scope=global}
{/block}
{block name='content'}
<div class="c_full">
<div class="grid_4">{$content}</div>
<div class="grid_4">{$content2}</div>
<div class="grid_4">{$content3}</div>
</div>
{/block}
5. Template: Two Columns in Two Rows with jQuery
Another example, imagine we need a template with two columns in two rows, but we also need jQuery added for a news slider.
Simply also add the jQuery block and it will be included when you use this template with a page.
{block name='top' append}
{$content2 = "{content block='content2'}" scope=global}
{$content3 = "{content block='content3'}" scope=global}
{$content4 = "{content block='content4'}" scope=global}
{/block}
{block name='content'}
<div class="c_full">
<div class="grid_6">{$content}</div>
<div class="grid_6">{$content2}</div>
</div>
<div class="c_full">
<div class="grid_6">{$content3}</div>
<div class="grid_6">{$content4}</div>
</div>
{/block}
{block name='jquery'}
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="uploads/_template/js/some.slider.js"></script>
{/block}
Well, this is all it takes... The possibilities are almost endless!
Now that I think about it, you can also use it for a multilingual website!
I recommend you try this out at the first site that you start on. I am sure you will also love it!
Comment Form
ReviewManager
ReviewManager
4 Comments
Hello Sir/Ma
Hope you having a good day.
I Would like to invite potential investors into the multinational growing global company.
Return Of Investment related Systems services.The brief about the kind of services is mentioned in the companies catalog and corporate website.
I would appreciate if you would take a look at this invitation opportunity put forward by Technologies board of directors and accept it.
Currently the company has clients,Investors,partners, distributors, resellers and others in more than 100+ countries across the globe.
As a company we are looking at growing and becoming one of the major multinational Investment Company in many countries across the globe.
We see that there is a huge potential and opportunities for the kind of services and products which we offer.
The company has a global vision for growth. We as a company are open for following options of legal investment options into the company .
Click here to join our platform today: http:/proven-zenith.com/?ref=roland2210
Are you tired of traditional online gaming platforms that lack transparency, fairness, and security? If so, look no further than BC.game!
As a leading blockchain-based gaming platform, BC.game offers a wide variety of games and features that prioritize privacy, anonymity, and responsible gambling. With our platform, you can enjoy a seamless gaming experience without sacrificing the security of your personal information or your financial transactions.
Here are just a few reasons why BC.game stands out from the competition:
Transparency: Unlike traditional online casinos, BC.game operates on a blockchain network that provides a completely transparent gaming experience. You can easily verify game results and payouts, ensuring that every game is fair and honest.
Security: With the power of blockchain technology, your personal information and financial transactions are protected by advanced security measures. Our platform utilizes the latest encryption technology to keep your data safe and secure.
Anonymity: BC.game is one of the few gaming platforms that offer complete anonymity. You don't need to provide any personal information to start playing. You can simply create an account and start playing right away!
Wide range of games: Whether you prefer classic casino games like roulette and blackjack or exciting crypto games like crash and hilo, BC.game has something for everyone. Our platform offers a wide variety of games, each with their own unique features and mechanics.
Social integration: BC.game is not just a gaming platform. We also offer social integration features that allow you to connect with other players from around the world. You can create your own profile, follow other players, and even share your gaming experiences on social media!
Rewards program: We believe in rewarding our loyal players, which is why we offer a comprehensive rewards program. You can earn coins and other rewards simply by playing games on our platform. The more you play, the more rewards you can earn!
At BC.game, we are committed to providing the best possible gaming experience for our players. Whether you are a seasoned player or new to online gaming, our platform offers everything you need to enjoy a safe, secure, and enjoyable gaming experience.
So why wait? Sign up for BC.game at https://bc.game/i-a94eqyqb-n/ today and start playing your favorite games in a fair, transparent, and secure environment. We look forward to seeing you on the platform!
Best regards,
The BC.game team
https://bc.game/i-a94eqyqb-n/
Good day,
I am Mr. David Antonio, Intl. Client Executive Banco Financials, Which is also a subsidiary of Fund Recovery Forensics. We are a private financial Investment company, We do give ( Business investments to start up companies, projects or business partnership. We also do crypto investment,Fund Recovery and we do give loan services ) We do grant loans to individuals and companies for Project finance, Business loans and Personal loan.
I am contacting you in regards to several potential business opportunities and loan service funding; ranging from project funding and business partnership. I came across your contact through a professional SEO Network.
I'm in search of a reliable company owner/partner with good return on investment, seeking funding for the purpose of mutual benefits,Or seeking a loan to fund a startup company or existing company project. I believe we can be able to assist each other in these endeavors. We also have a crypto company
that anyone can invest in and watch your portforlio increase over time in values as the market grows, Alongside support from our social media influencers and revenue generated from our technology and services rendered, together we will expand.
We Fund companies on:
1 IT Project
2 Oil & Gas
3 Resort and Hotel project
4 Industrial Project and Waste Management project
5 Hospital Project
6 Educational Sector
7 Real estates
8 Loan Services
9 Construction
10 Cryptocurrency investment and fund recovery ( Through the Financial Conduct Authority | FCA and FinCEN | Financial Crimes Enforcement Network ).
Kindly revert back to me via email davidantoniobanco@gmail.com if you deem it necessary for me to elaborate more in this regard, I await your affirmative response so we can proceed.
Esteem Regards,
David Antonio
Banco Financials & Fund Recovery Forensics
Nice tutorial! It is also possible to get content prior to the block by using "prepend" instead of "append". Maybe you can add an example to your "notes to yourself" ;)