Jump to content

v6 Question concerning Smarty


Dirty Butter

Recommended Posts

If you DO check it the data will be passed through the Smarty parser. This means you can add smarty syntax for conditions, including templates, etc..

 

This means that anything in curly brackets e.g. {$EXAMPLE_MACRO} will be parsed. We had to add a switch instead of having it on as standard as there may be documents before this feature was added with curly brackets which do not contain Smarty code. This causes a fatal error and white screen. 

 

So.. If "Parse Smarty Tags" is enabled the following will not show in the output but with it disabled it will. 

{* this is a comment *}
Link to comment
Share on other sites

Thanks! It's always bothered me that I couldn't temporarily comment out something in a document, but had to delete it and write it again when needed.

 

So IF I understand your explanation I can now check that box and use {* ... *} to comment out something, and it will now show on the Store Front.

Link to comment
Share on other sites

The contents of a document, product or category description are/were treated exactly as the value of a variable. Assign the value to {$contents} and that is what gets put in the template and sent to the browser. (Smarty has a small set of modifiers that can affect the value of the variable.)

 

As it happens, said content is meant to be displayed as HTML, so any HTML code you managed to get the editor to make, that's what got displayed.

 

Now, from how this is explained, you can also code for Smarty logic -- in documents. (Maybe to be seen in prod/cat descriptions?)

 

"Anything in curly brackets e.g. {$EXAMPLE_MACRO} will be parsed."

 

Assuming you have a variable to act upon, you can 'tweak' the document contents based on the value of that variable. As such, when the Cubecart class is gathering the data for a document, the document's contents are passed through the Smarty parser and the value of the variable is used.

 

The question I have is: what hook would we use so that custom data can be assigned to Smarty variables prior to sending doc_content through Smarty->fetch()? I like 'class.cubecart.document_widgets' but it comes after the fetching. We may want a hook in CubeCart->getDocument().

 

So, it seems the data we have available to us is both limited and unlimited. When Smarty is parsing and compiling, it affords us the use of any Class that is currently instantiated and loaded functions.

 

 

Oh, I also now see how everything submitted (GET, POST, COOKIEs) bypasses the sanitizer. A copy is made ['RAW'], then the originals are sanitized. If a controller would otherwise enjoy unsanitized POSTed values, the controller must now use the ['RAW'] copy.

 

There is a setting in the editor's config file that may offer some obstacles to using Smarty's {foreach} looping structure. That setting was to stop getting the emails messed up.

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.protectedSource

Link to comment
Share on other sites

This is nice!...

 

As an experiment, I added

{debug}

to the bottom of the Homepage Document contents.

 

I got Smarty's DEBUG console!!!

 

Not much is available: 22 variables of which the current language pack ($LANG) and the current configuration ($CONFIG) are there. {$IS_USER} can be used for alternate content when a customer is logged in. The rest are inconsequential.

Link to comment
Share on other sites

We found the same thing. The smarty debug tool alone is just too basic.. but then I suppose it is only supposed to debug the Smarty library so for its purpose its spot on. :) 


 

The question I have is: what hook would we use so that custom data can be assigned to Smarty variables prior to sending doc_content through Smarty->fetch()? I like 'class.cubecart.document_widgets' but it comes after the fetching. We may want a hook in CubeCart->getDocument().

 

Can you give me an example of when you might want to do this? My pepper shot brain works far better with real life examples. :P

 

It may well be nice to have a pre and post parser of our own as a hook. I'd expect the GUI class can handle this as from memory it extends Smarty. 

Link to comment
Share on other sites

"Can you give me an example of when you might want to [assign custom data to Smarty variables prior to sending doc_content through Smarty->fetch()]?"

 

Ironically, the div block (in Kurouto) that contains the Homepage document is ID'd as "announcement". So, let's make an announcement. Code the following in the Homepage document:

 

CubeCart v6 beta launched & all versions now open source!

 

Today it is of greatest pleasure to make a number of significant announcements!

  • CubeCart is celebrating its tenth birthday as a private UK company.
  • CubeCart {$latest_v6_version} and {$latest_v5_version} are available for download.
  • CubeCart version 6, 5, 4 & 3 are all now open source under the GPL 3.0 licence.
  • The all new CubeCart Extensions Marketplace has been launched.
  • Enterprise Level technical support plans are now available including managed services.

We are expecting a huge amount of questions so have tried to answer most below.

{* switch to source mode *}

{if $OPEN_SOURCE_FAQ}{foreach from=$OPEN_SOURCE_FAQ item=faq}

<h3>{$faq.title}</h3>

<div class="faq_article">{$faq.article}</div>

{/foreach}{/if}

 

 

We now need a hook to have code that will retrieve an appropriate $recordset from a database table containing these faq's, and to code:

Smarty->assign('OPEN_SOURCE_FAQ',$recordset);

Smarty->assign('latest_v6_version',"6.0.0.b2"); // version is queried from somewhere

Smarty->assign('latest_v5_version',"5.2.16"); // version is queried from somewhere

 

GUI does not extend from anything.

Link to comment
Share on other sites

I see. Without adding any new code hooks I don't see why this can't be done with the hook "controller.index" found in the controllers/controller.index.php file. 

 

However this will run on every page load. 

 

Alternatively if that doesn't work maybe a new hook needs to be added at the start of classes/Cubecart->displayHomePage

 

I can't think of another way to do it unless we create a function or hook in the GUI class to do this work before Smarty->assign.

Link to comment
Share on other sites

If we restrict this capability to any and all documents (as opposed to product descriptions and category descriptions, which may have their own hooks), and not just the Homepage document, then a hook in CubeCart->getDocument() before Smarty->fetch() is the most appropriate location.

 

And, anyway, there is already a hook in displayHomepage() at the bottom that can be used to:

if(!empty($home['doc_parse'])){ // $home is not false and has the parse flag enabled
  $home['doc_content'] = Smarty->fetch('string:'.$home['doc_content']); // parse the contents
  Smarty->assign('DOCUMENT', array('title'  => $home['doc_name'],'content' => $home['doc_content']); // reassign
}
Link to comment
Share on other sites

  • 1 year later...

Trying to put some "logic" within a document with "Smarty Tags". They work in a templates, however they do not work in a "documents". Tried with "Parse Smarty Tags" box checked and unchecked - the same behavior. Generally... My steps...

* Created an empty document (title, etc.).
* Start editing a content.
* Switch to "Source"
* Inserted

<p>{$CART_TOTAL}</p>

When I see the document, I have only:

<p></p>

In the "Smarty Debugger" the variable exists. Also tried a couple other variables (Smarty objects) with the same result.

WHAT I"M DOING WRONG?

PS. Also curious, if "smarty tags" processing available in the "product description".
 

Link to comment
Share on other sites

CubeCart has, so far, been coded to pass a Document's Contents (but not Product Descriptions or Category Descriptions) through a Smarty parser.

There are a few constraints, however.

The Document Content does not join into a skin template. The Contents are treated as a separate stand apart "string" input to the parser and the parser is called when CubeCart is collecting and organizing data to assign to variables (said variables are in the template). In other words, the value assigned for CART_TOTAL must already be known to Smarty for the Document Contents variable to be replaced by that value.

Through the use of provided hooks, it may be possible to have code that will send the product's description through the Smarty parser.

Link to comment
Share on other sites

So, you're saying, that "smarty" within the document does not have access to the global objects? When I put the command {debug} in the document, I'm getting a popup with all variables defined "on the template level". Should I access them differently? I tried to look at $smarty and $smarty_data (with |@var_dump), but they return NULL. How could I see what is available within "document smarty" versus "template smarty"?

Link to comment
Share on other sites

It is best to use {debug} at only one place at a time. (With some code changes to Smarty, it is possible to have multiple popups, one for each {debug}.) When Smarty processes the {debug} command, it gets replaced by a javascript-powered popup. The Smarty Debug console shows only those variables that have been assign() into Smarty's template variable array up to that point - the store's CONFIG array and the language LANG array for example.

CubeCart will process all of the main content template (product, category, document, customer account, checkout, etc), tell Smarty to render that template, then work on the various side boxes, rendering each box template in turn.

When you get the popup from the {debug} in the document's contents, do not close it. Then, delete the {debug} in the doc's contents and add {debug} to the end of the skin template main.php. You should get a second popup, as opposed to the first being updated. Compare what is available between the two popups.

It's tricky about what global objects Smarty has access to.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...