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

How find where will data pass?

 
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
Game Over!
Smarty Rookie


Joined: 01 May 2019
Posts: 10

PostPosted: Sat May 11, 2019 2:04 pm    Post subject: How find where will data pass? Reply with quote

Hello guys.

I asked my question in IRC and sb told me ask it on the forum.

I have a website that coded by 2-3 person and I havn't any connection with that people. I even just started learning Smarty but have experience with Laravel, WP and some other frameworks.

but the problem is I have a PHP file that send some data to specific template. It seems PHP files will call TPL files with the same name for eg:
Code:
Test.php ==> will pass data to ==> Test.tpl


because they don't use
Code:
$Smarty->display(Test.tpl);
in the project.

1. so I just wanna to know where can I find which TPL file data will pass ?
I found Test.TPL but when I change Test.TPL file , nothing will happen.


2. How can I call all of my js/css files ?Do you have any standard way? because this project have many js and css files and some of them are same Neutral for example they loaded Jquery many times with different versions. so I wanna to unify them.

thanks in advance.
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sat May 11, 2019 11:29 pm    Post subject: Reply with quote

I am not aware of how one can get Smarty to do its thing using means other than its published API. That is, fetch() and display() are the only means I know of.

Of course, one can create a Class set of methods and extend it onto Smarty.

Javascript and CSS files are page resources, called by the browser according to the resource links in the HTML. To unify (standardize) those resources, one could use {include element.head.tpl} and {include element.bottom.tpl} where the contents of each are HTML links to resources typically found in the <head> section, and at the bottom of the page.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon May 13, 2019 5:22 am    Post subject: Reply with quote

Finding the entry point to Smarty in the code is rather simple.
Place brakpoint at the start of Smarty_Internal_TemplateBase::_execute and when it is hit, look at the call stack.

What to JS and CSS, you do not call them from Smarty. They are called by the browser and these calls end at webserver before PHP.
Back to top
View user's profile Send private message
Game Over!
Smarty Rookie


Joined: 01 May 2019
Posts: 10

PostPosted: Tue May 14, 2019 6:40 am    Post subject: Reply with quote

bsmither wrote:
I am not aware of how one can get Smarty to do its thing using means other than its published API. That is, fetch() and display() are the only means I know of.

Of course, one can create a Class set of methods and extend it onto Smarty.

Javascript and CSS files are page resources, called by the browser according to the resource links in the HTML. To unify (standardize) those resources, one could use {include element.head.tpl} and {include element.bottom.tpl} where the contents of each are HTML links to resources typically found in the <head> section, and at the bottom of the page.

Thanks a bunch
when I said "call" I meant "include" . sorry for my bad English.
I mean how should I include very much libraries and where put them

for example project uses "Ace admin template" and it needs "jquery".
another library like bootstrap needs "jquery".
font-awesome also needs "jquery".
do you have any specific way to unify them?
that's what I'm looking for.

AnrDaemon wrote:
Finding the entry point to Smarty in the code is rather simple.
Place brakpoint at the start of Smarty_Internal_TemplateBase::_execute and when it is hit, look at the call stack.

What to JS and CSS, you do not call them from Smarty. They are called by the browser and these calls end at webserver before PHP.

Thanks a billion.
first I should say code is on server so I can't insert breakpoint or ...
In addition I edited this file :
Code:
\lib\Smarty-3.1.10\sysplugins\smarty_internal_templatebase.php

and did this changes :

Code:

    public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
    {
        print_r($template);
// other code ...

and it will give me the TPL file like "public-layout.tpl"
but I also found another way. I insert this code into TPL file :
Code:
{get_defined_var|@print_r}

and it will show me man array elements. but I need just this section :
Code:

Array
(
    [_smarty_tpl] => Smarty_Internal_Template Object
        (
            [cache_id] =>
            [compile_id] =>
            [caching] =>
            [cache_lifetime] => 3600
            [template_resource] => file:public-home-default-.tpl
            [mustCompile] =>
            [has_nocache_code] =>
            [properties] => Array
                (
                    [file_dependency] => Array
                        (
                            [a856d7a45451493a2e4765868737118993655390] => Array
                                (
                                    [0] =>static/custom_tpl/public-home-default-.tpl
                                    [1] => 1557748503
                                    [2] => file
                                )

                        )

                    [nocache_hash] => 11611173755c56a6f22ba350-74363982
                    [function] => Array
                        (
                        )

                    [version] => Smarty-3.1.10
                    [unifunc] => content_5c56a867f27004_71174592
                    [variables] => Array
                        (
                            [MyTitle] => 0
                            [URL] => 0
                            [Lang] => 0
                            [myvar] => 0
                            [feature] => 0
                            [step_index] => 0
                            [step] => 0
                            [brand] => 0
                            [advantage_index] => 0
                            [advantage] => 0
                            [userid] => 0
                            [tender] => 0
                            [Usernamehost] => 0
                        )

                    [has_nocache_code] =>
                )


this line :
static/custom_tpl/public-home-default-.tpl

so how can I access this member of array?
thanks in advance
and sorry if I'm newbie in Smarty
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat May 18, 2019 2:25 pm    Post subject: Reply with quote

Run a copy of the website locally, and use debugger already.
Back to top
View user's profile Send private message
Game Over!
Smarty Rookie


Joined: 01 May 2019
Posts: 10

PostPosted: Sun May 19, 2019 10:50 am    Post subject: Reply with quote

AnrDaemon wrote:
Run a copy of the website locally, and use debugger already.


Thanks for replying my message.
I can't run it locally .... just it's DB size is about 1.5GB and have many compiled and tpl files.that's why I'm looking for a way to debug it on sharing hosting.

so is there anyway let me access to ?
Code:
_smarty_tpl=>properties=>file_dependency



Thanks a bunch
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun May 19, 2019 6:19 pm    Post subject: Reply with quote

Only 1.5GB? That's nothing.
Not to mention, you don't need full database, only enough rows to run the code.
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sun May 19, 2019 7:05 pm    Post subject: Reply with quote

I think you cannot get to file_dependency. I think that is because this array is created after the template is compiled, but you may be asking for it before the template is compiled.

Instead, in the template, ask for these Smarty variables. Both could give you the same response.
Code:
FilePath:{$smarty.template_object->source->filepath}<br />
ParentPath:{$smarty.template_object->parent->source->filepath}<br />
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun May 19, 2019 11:13 pm    Post subject: Reply with quote

I wonder, why he's trying to access internal Smarty variables.
Back to top
View user's profile Send private message
Game Over!
Smarty Rookie


Joined: 01 May 2019
Posts: 10

PostPosted: Wed May 22, 2019 1:02 pm    Post subject: Reply with quote

AnrDaemon wrote:
Only 1.5GB? That's nothing.
Not to mention, you don't need full database, only enough rows to run the code.


There is 195 table Confused Sad
I should check them if there is any relationship and I also don't have much time.

bsmither wrote:
I think you cannot get to file_dependency. I think that is because this array is created after the template is compiled, but you may be asking for it before the template is compiled.

Instead, in the template, ask for these Smarty variables. Both could give you the same response.
Code:
FilePath:{$smarty.template_object->source->filepath}<br />
ParentPath:{$smarty.template_object->parent->source->filepath}<br />


Thanks a bunch

AnrDaemon wrote:
I wonder, why he's trying to access internal Smarty variables.


It's simple. I have many tpl files and folders, many user roles and many languages for example :

Code:
// Logged-in users
site.com/en/user/privacy
site.com/es/user/privacy

// Guest user that not logged-in
site.com/en/public/privacy
site.com/es/public/privacy

// Admin users that logged-in
site.com/en/admin/privacy
site.com/es/admin/privacy

and all of these files have different content Neutral
I don't made this project and I should develop it and don't know anything about the structure and also I've never done this before with Smarty.
so I have 2 problems here


1. I don't know if I request
Code:
site.com/user/public/privacy
where is the tpl file? as you know for example in the Laravel we have "Route" file and we can understand where the "TPL" and "controller" files come from but it seems Smarty doesn't has "route" so I need to print out tpl file path like this
Code:
FilePath:{$smarty.template_object->source->filepath}<br />
ParentPath:{$smarty.template_object->parent->source->filepath}<br />
but this code is useful whern you know which TPL is loaded. but what should I do when I don't know which TPL is loaded ?
Ofcourse this post helped me a lot but it doesn't print full path. so I need a similar code to do print fully path of TPL file.

Thanks in advance
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu May 23, 2019 6:37 am    Post subject: Reply with quote

Then just bring up a development VM locally, load a copy of the website there and use normal debugger to step through the code.
Or hire a qualified specialist, if you have no time for it yourself.
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Fri May 24, 2019 9:48 am    Post subject: Reply with quote

What makes a template engine useful is that the application determines important things and then a conclusion is assigned to a Smarty variable: a specific language, a defined set of instructions, etc., all using just the same template.

With:
Code:
site.com/user/public/privacy
you ask where is the TPL file.

Building a web page can have many TPL files, each contributing a specific area: top banner, bottom footer, left navigation, etc.

So, you may be asking, how can I determine what are all the template files that were used in building this page?

I have no answer, but it is an interesting question.
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