|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
PierceMcGeough Smarty n00b
Joined: 10 Jan 2014 Posts: 3
|
Posted: Fri Jan 10, 2014 10:26 am Post subject: Is it possible to extract content as a smarty variable |
|
|
I have a layout template (below is an example but much less complex).
Code: | <body>
<header>
<nav></nav>
</header>
<div class="main">
<div class="left">
{include file=$content.left}
</div>
<div class="right">
{include file=$content.right}
</div>
</div>
<footer></footer>
{include file=$js_scripts}
</body> |
The folder structure lets me have the layout file and then folders for the content. The problem with this is I need multiple template pages and once the content requires some inline code it will change. There are also pages that might not require the js_scripts which will result in a smarty error.
Code: | views/layout
layout_1.tpl
layout_2.tpl
views/pages/mypage
left_content.tpl
right_content.tpl
js_scripts.tpl |
Is it possible to extract content from a page and assign it to a variable instead of including a file which may not even be needed. Im thinking something along the lines of this which will leave me with one page and the content together in once place
Layout.tpl
Code: | <body>
<header>
<nav></nav>
</header>
<div class="main">
<div class="left">
{$content.left}
</div>
<div class="right">
{$content.right}
</div>
</div>
<footer></footer>
{$js_scripts}
</body> |
mypage.tpl
Code: | {extract variable $content.left}
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem, tempore, quae, cum, consequatur quisquam totam facilis illo blanditiis porro in quidem repudiandae necessitatibus dolores eius quam sequi labore impedit id.</p>
{/extract}
{extract variable $content.right}
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
{/extract}
{extract variable $js_scripts}
<script src="js/jquery.js"></script>
<script>
$(document).ready(function() {
$('#id').click(function(){
// run code
});
});
</script>
{/extract} |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|