View previous topic :: View next topic |
Author |
Message |
brainwave Smarty Rookie
Joined: 09 Jul 2003 Posts: 22
|
Posted: Mon Nov 17, 2003 9:13 am Post subject: predefined html-code? |
|
|
Hi,
is it possible with smarty to define HTML-code like a function in templates and use it again and again?
I mean I have this HTML-Code:
<div class="errorbox">{$errormessage}</div>
Then i get an funktion like this in my template:
{errorbox}ERROR ERROR ERROR YOUR SYSTEM WILL EXPLODE IN 10 SECONDS{/errorbox}
And the result is:
<div class="errorbox">ERROR ERROR ERROR YOUR...</div>
Greetings
Sascha |
|
Back to top |
|
brainwave Smarty Rookie
Joined: 09 Jul 2003 Posts: 22
|
Posted: Mon Nov 17, 2003 1:42 pm Post subject: |
|
|
can I do this with the block modifiers? |
|
Back to top |
|
rainco Smarty Rookie
Joined: 13 Oct 2003 Posts: 31 Location: Germany
|
Posted: Mon Nov 17, 2003 1:50 pm Post subject: |
|
|
yes, it is possible with block-functions. but the better method is an include i think:
{include file="errorbox.tpl" message="Your box will explode in 10 sec"}
and in errorbox.tpl:
<div class="errorbox">{$message}</div>
thats all. so you do not need any php-code for that |
|
Back to top |
|
brainwave Smarty Rookie
Joined: 09 Jul 2003 Posts: 22
|
Posted: Mon Nov 17, 2003 1:58 pm Post subject: |
|
|
but including files is slower than the modifier method or does not matter?
I search for a posibility to include often used HTML-code in functions. I wont replace all my modifications in all template files again and again. I will edit ohne file with my code. |
|
Back to top |
|
rainco Smarty Rookie
Joined: 13 Oct 2003 Posts: 31 Location: Germany
|
Posted: Mon Nov 17, 2003 2:39 pm Post subject: |
|
|
brainwave wrote: | but including files is slower than the modifier method or does not matter? |
i don't think includes are slower. maybe faster. just test it out. |
|
Back to top |
|
brainwave Smarty Rookie
Joined: 09 Jul 2003 Posts: 22
|
Posted: Mon Nov 17, 2003 2:48 pm Post subject: |
|
|
ok thx! I will test it!
but how can I use {section} with an include!
for example I have this code:
{section name=test loop=$test}
<span class="headline">{$test[test].titel}</span>
{/section}
I want it in the include file. But how?
I have to made one include file for the opening tags above the section and 2nd include for the closing tags after the section? but I think it's not the best solution. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Nov 17, 2003 2:52 pm Post subject: |
|
|
i think include is significantly slower than using a block function.
instead of writing many block-plugins you can write a generic block-plugin-function and register it under many different names. inside the plugin you can have a look in $smarty->_tag_stack with which name the function was called and translate the block-contents accordingly.
even faster than many block-plugins would be a prefilter, that translates your {errrocode}...{/errorcode} into html before the template is compiled. |
|
Back to top |
|
rainco Smarty Rookie
Joined: 13 Oct 2003 Posts: 31 Location: Germany
|
Posted: Mon Nov 17, 2003 2:57 pm Post subject: |
|
|
if you want to do it with includes you can put the whole section in the include:
{include file="include.tpl" test=$test}
and in include.tpl:
{section name=test loop=$test}
<span class="headline">{$test[test].titel}</span>
{/section} |
|
Back to top |
|
brainwave Smarty Rookie
Joined: 09 Jul 2003 Posts: 22
|
Posted: Mon Nov 17, 2003 3:10 pm Post subject: |
|
|
I think I can't use include for my issues!
I have some templates that give out error messages. And this error messges I want to put them into an errorbox!
my template code is like this:
{if $error == 1}
FATAL ERROR
{elseif $error == 2}
NORMAL ERROR
.....
{/if}
I thougt, I can put this easely into this:
{errorbox}
{if $error == 1}
FATAL ERROR
{elseif $error == 2}
NORMAL ERROR
.....
{/if}
{/errorbox}
and the error's will be displayed in the box.
Just I'am very confused how to use prefilters, block funktions or so on...?!? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Nov 17, 2003 3:28 pm Post subject: |
|
|
sorry, i didn't want to confuse you. maybe start with
block.errorbox.php
[php:1:58c4dcf991]
function smarty_block_errorbox($params, $content, &$smarty) {
if (isset($content)) {
return '<div class="errorbox">' . $content . '</div>';
}
}
[/php:1:58c4dcf991]
in my former post i just wanted to say, that it's just not very efficient for tens or hundreds of such tags. but for a few ones it should work ok. |
|
Back to top |
|
brainwave Smarty Rookie
Joined: 09 Jul 2003 Posts: 22
|
Posted: Mon Nov 17, 2003 3:37 pm Post subject: |
|
|
great! some code and I no more confused! thx!
one question about this:
I want to use some kind of this blocks for errorbox, infobox, headlines! To make changes very quick and easy! Thats my opinion behind this.
But whats your opinion? Do you think it's a good idea or it's better to hardcode alle the html-tags in the template files?! |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Nov 17, 2003 3:47 pm Post subject: |
|
|
i think in theory you should keep the <div>s static in the template and only change the stylesheets if you want to change their appearance. i don't know how good this works in practice (i'm no webdesigner). |
|
Back to top |
|
|