Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

What is getTags() supposed to return?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Jojosito
Smarty n00b


Joined: 09 May 2018
Posts: 3

PostPosted: Wed May 09, 2018 9:48 am    Post subject: What is getTags() supposed to return? Reply with quote

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
View user's profile Send private message
scuzzy
Smarty Regular


Joined: 31 Aug 2003
Posts: 84

PostPosted: Wed May 09, 2018 10:27 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed May 09, 2018 10:34 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed May 09, 2018 10:38 am    Post subject: Reply with quote

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
View user's profile Send private message
Jojosito
Smarty n00b


Joined: 09 May 2018
Posts: 3

PostPosted: Wed May 09, 2018 10:45 am    Post subject: Reply with quote

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
View user's profile Send private message
scuzzy
Smarty Regular


Joined: 31 Aug 2003
Posts: 84

PostPosted: Wed May 09, 2018 10:51 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed May 09, 2018 10:51 am    Post subject: Reply with quote

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
View user's profile Send private message
scuzzy
Smarty Regular


Joined: 31 Aug 2003
Posts: 84

PostPosted: Wed May 09, 2018 10:54 am    Post subject: Reply with quote

AnrDaemon wrote:
What stops the user from inserting...

Wouldnt the security settings inherent in smarty would be enough? eg https://www.smarty.net/docs/en/advanced.features.tpl#advanced.features.security


Last edited by scuzzy on Wed May 09, 2018 10:57 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Jojosito
Smarty n00b


Joined: 09 May 2018
Posts: 3

PostPosted: Wed May 09, 2018 10:56 am    Post subject: Reply with quote

Ok, I will just set all attributes. Thanks for the replies!
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed May 09, 2018 11:19 am    Post subject: Reply with quote

scuzzy wrote:
AnrDaemon wrote:
What stops the user from inserting...

Wouldnt the security settings inherent in smarty would be enough? eg https://www.smarty.net/docs/en/advanced.features.tpl#advanced.features.security

Would be, if you waste a tremendous amount of time configuiring it.

Just use https://github.com/Gemorroj/xBBCode
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP