Why duplicate "send_to_friend.tpl" file + $view + var directory

Hello Developers,



I am working on my first addon and of course I have many questions but keeping it to a few that seem important to know just now…



Using the latest version of cs-cart I found these two files are identical:


skins:base:customer:addons:send_to_friend:blocks:products_tabs
send_to_friend.tpl
var:skins_repository:base:customer:addons:send_to_friend:blocks:product_tabs
send_to_friend.tpl


Can anyone tell me why there are two identical files like this?



What is the “var” directory for? My initial reaction would have been it’s for “variable” data (compiled code, cache etc.) however there are files there that are just part of code, in particular under: var:skins_repository:base



And finally, what is the global variable $view for? I’m not actually sure in cs-cart what a view is. Is it just what will be “viewed” or are the various “views” that you can show and so on… I just need to conceptually know what it’s about.



Any help greatly appreciated as it’s always hard when you are first starting off and know essentially nothing.



Reg

Var/skins_repository

= ‘Base’ Template + ‘Your Skin’ Template = ‘Your Skin’ Template.



ie:

base + basic = basic skin

base + default_red = default_red skin



Var is essentially used for the first generation on the chosen skin and is the singular code base to which all skins are formed from.



In your example: var is the original code, copied to skins to create your skin.



End result: leave it where it is.



not certain what you mean re: $view, someone else will chime in


[quote name=‘Reg’]Hello Developers,



I am working on my first addon and of course I have many questions but keeping it to a few that seem important to know just now…



Using the latest version of cs-cart I found these two files are identical:


skins:base:customer:addons:send_to_friend:blocks:products_tabs
send_to_friend.tpl
var:skins_repository:base:customer:addons:send_to_friend:blocks:product_tabs
send_to_friend.tpl
Can anyone tell me why there are two identical files like this?



What is the “var” directory for? My initial reaction would have been it’s for “variable” data (compiled code, cache etc.) however there are files there that are just part of code, in particular under: var:skins_repository:base



And finally, what is the global variable $view for? I’m not actually sure in cs-cart what a view is. Is it just what will be “viewed” or are the various “views” that you can show and so on… I just need to conceptually know what it’s about.



Any help greatly appreciated as it’s always hard when you are first starting off and know essentially nothing.



Reg[/quote]

view is a pointer to the templater class object and is stored in the Registry for use within controllers.



I.e.


$view = Registry::get('view');
$view->assign('template_variable_name', "hello world");


Will make the template variable:

{$template_variable_name} have the value of “hello world” in all templates in the context of the controller. I.e. the basic controller areas are ‘admin’, ‘customer’ and ‘mail’.



There is a separate ‘view’ for mail and either ‘customer’ or ‘admin’ depending on the AREA you are operating in.

[quote name=‘tbirnseth’]view is a pointer to the templater class object and is stored in the Registry for use within controllers.



I.e.


$view = Registry::get('view');
$view->assign('template_variable_name', "hello world");


Will make the template variable:

{$template_variable_name} have the value of “hello world” in all templates in the context of the controller. I.e. the basic controller areas are ‘admin’, ‘customer’ and ‘mail’.



There is a separate ‘view’ for mail and either ‘customer’ or ‘admin’ depending on the AREA you are operating in.[/QUOTE]



So is $view the Smarty class extended to be the Templater class and therefore it’s all the data rendered by the smarty engine?

Ah, that explains it about the “var” dir., got it - thanks.

Basically, yes. Class templater extends class smarty. It’s what adds hooks and a few other “tags” and “modifiers” to the smarty class. It processes the smarty data and renders any html that is associated with it.



But note that in cs-cart, there is very little html rendered by the smarty/templater class itself. Smarty is used almost exclusively for control and they use included files as functions…

[quote name=‘tbirnseth’]But note that in cs-cart, there is very little html rendered by the smarty/templater class itself. Smarty is used almost exclusively for control and they use included files as functions…[/QUOTE]



Hm, it’s starting to come in to focus now. I did search through the code and got 79 matches in 42 files for the code “$view->display(…)” - is this the primary way of displaying the data to the browser? The reason I ask is because to me this ultimately goes down to the smarty engine to do so to my way of thinking smarty would be doing the rendering.



Since you say it’s not smarty doing most of the rendering that means there is something I am misunderstanding in what you are saying. And if it’s not smarty, where is the primary conversion of data-to-html and subsequently push out the browser.



To qualify this question let me explain that my primary experience in largish php systems is Drupal. In Drupal everything is stored in objects with huge multi-dimensional arrays (over time being converted to more OO and less arrays) and then the template engine renders all that data into HTML… so that is the concept I am familiar with (with some adjustments to the methodology now that we have AJAX).



The way this looks is like data is stored in $view and then as and when they need to they render a template file with $view->display(…) which is a little bit of a different concept since it doesn’t look like all the creation of the HTML output to the browser is done at once but in various discrete steps instead – is that close at all to how it’s working?



Thanks,

Reg

My understanding from working with it (versus a detailed code analysis) is that the $view->display() method executes the template engine to process the template(s).



Note that many places the view is accessed directly by reference from the Registry via: Registry::get(‘view’)->assign(‘var’, ‘value’);



I’ve done a lot of work with cs-cart and I’ve never had to do a $view->display(). I’ve modified a lot of controllers to add template variables and/or to modify existing ones but then that’s all just made available to the templates as template variables.



When I say that smarty isn’t rendering html, I was referring to the smarty functions that do things like generate tables, radio buttons, etc. This is all done “natively” in cs-cart. They do not utilize any (that I’ve seen) of the smarty generated html.



You kind of have to think of smarty like a “pre processor”. I.e. it provides a control structure and the ability to conditionally include stuff, but it ultimately means that one has to write the basic html. Of course, included files allow for reasonably good “reuse” versus having to duplicate stuff all over the place. But contrary to good-practices, cs-cart puts a lot of business logic into the UI layer.



You’re going to have a great time when you start to try to unwind what they do in Javascript! :slight_smile:

Thanks!



I think I’ve got enough of a handle on it now from everything you said to move forward.