View previous topic :: View next topic |
Author |
Message |
Jojosito Smarty n00b
Joined: 09 May 2018 Posts: 3
|
Posted: Wed May 09, 2018 9:48 am Post subject: What is getTags() supposed to return? |
|
|
Hi,
I am trying to get the tags which are in a template. My template looks like this:
Code: |
Product Information: Name:
{$name}
Strings:
{$string1} und {$string2}.
{$string3}
Das war's!
|
I try to get the tags:
Code: |
$tags = $smarty->getTags($template);
foreach ($tags as $tag)
{
echo('tag: '.var_dump_string($tag).PHP_EOL);
}
|
This is what I get:
Code: |
tag: array(2) { [0]=> string(24) "private_print_expression" [1]=> array(0) { } }
tag: array(2) { [0]=> string(24) "private_print_expression" [1]=> array(0) { } }
tag: array(2) { [0]=> string(24) "private_print_expression" [1]=> array(0) { } }
tag: array(2) { [0]=> string(24) "private_print_expression" [1]=> array(0) { } }
|
There are 4 tags, which is what I expect, but no useful information.
I would like to get the names of the tags, i.e. "name", "string1", "string2", "string3". Is this possible?
Kind regards,
Jojo |
|
Back to top |
|
scuzzy Smarty Regular
Joined: 31 Aug 2003 Posts: 84
|
Posted: Wed May 09, 2018 10:27 am Post subject: |
|
|
I've been stumbling around the parser/lexer/compilers to try to solve a problem myself, but...
"Return array of tag/attributes of all tags used by an template"
private_print_expression is represednt by class Smarty_Internal_Compile_Private_Print_Expression which I belive would just be a regular echo tag eg {$foo}
Aka this looks like a rather internal function, and perhapps not what you're chasing. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed May 09, 2018 10:34 am Post subject: |
|
|
Code: | <?php
require_once __DIR__ . '/smarty-config.php';
$tpl = $smarty->createTemplate(__FILE__);
$tags = $smarty->getTags($tpl);
foreach($tags as $name => $tag)
{
print "$name: ";
var_dump($tag);
}
__halt_compiler()
?>{if empty($block)}{$item}{else}<{$block}>{/if}); |
But my question is - what the hell you are trying to actually achieve? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed May 09, 2018 10:38 am Post subject: |
|
|
scuzzy wrote: | this looks like a rather internal function |
Why did I read that as "infernal"?…
Either way, did you noticed that the function marked experimental?
So, the question is the same - what do you ACTUALLY want to do? |
|
Back to top |
|
Jojosito Smarty n00b
Joined: 09 May 2018 Posts: 3
|
Posted: Wed May 09, 2018 10:45 am Post subject: |
|
|
Thanks for the replies!
What I'm trying to achieve:
The template is a product description for ebay. The user can write a product description and use attributes of the product as smarty tags (e.g. the name of the product {$name}).
I have to get the values of the product attributes from a database. Therefore I would like to know which tags are used, so that I don't have to fetch all tags from the db.
The code example gives me "1", "2", "3" as names.
Cheers! |
|
Back to top |
|
scuzzy Smarty Regular
Joined: 31 Aug 2003 Posts: 84
|
Posted: Wed May 09, 2018 10:51 am Post subject: |
|
|
I doubt the DB "cost" of fetching all fields, and having some of them not get used is worth trying to code an elaborate solution for.
Last edited by scuzzy on Wed May 09, 2018 10:52 am; edited 1 time in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed May 09, 2018 10:51 am Post subject: |
|
|
What stops the user from inserting
Code: | {"/etc/shadow"|file_get_contents} |
instead?
Letting a random user write code for your application is a VERY, VERY, VERY bad idea.
Use bbcode parser, it's much safer by design. |
|
Back to top |
|
scuzzy Smarty Regular
Joined: 31 Aug 2003 Posts: 84
|
|
Back to top |
|
Jojosito Smarty n00b
Joined: 09 May 2018 Posts: 3
|
Posted: Wed May 09, 2018 10:56 am Post subject: |
|
|
Ok, I will just set all attributes. Thanks for the replies! |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
|