Smarty Caching | {content block} variable returns null/blank

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
leroy
New Member
New Member
Posts: 2
Joined: Thu Jun 28, 2018 9:18 pm

Smarty Caching | {content block} variable returns null/blank

Post by leroy »

Hi,

I'm quite new with smarty and I have a question about problems after I activated "Smarty caching".

I have a template where some variables are defined. The input of these values are provided in when someone fills in certain fields when creating a page (and this template selected).

This is the template:

Code: Select all

{process_pagedata}

{content block="menusubtitle" label="Menu subtitel" oneline=true assign="noassign"}
{content block="sitemapCheck" oneline=true default=0 assign="sitemapCheck" label="Exclude page from sitemap? ('1' excludes page)"}
{content block="sitemapFooterCheck" oneline=true default=0 assign="sitemapFooterCheck" label="Exclude page from footer sitemap? ('1' excludes page)"}
{content block="custom_meta_description"  assign="custom_meta_description" wysiwyg="false" label="Meta description" oneline="true" maxlength="160"}
{content block="custom_meta_keywords" assign="custom_meta_keywords" wysiwyg="false" label="Meta keywords (max 5-10 komma gescheiden woorden!)" oneline="true" maxlength="500"}


{content block="custom_alternate_hreflang_nl" assign="custom_alternate_hreflang_nl" wysiwyg="false" label="Alternate hreflang alias voor Nederlandse pagina" oneline="true"}
{content block="custom_alternate_hreflang_en" assign="custom_alternate_hreflang_en" wysiwyg="false" label="Alternate hreflang alias voor Engelse pagina" oneline="true"}
{content block="custom_alternate_hreflang_de" assign="custom_alternate_hreflang_de" wysiwyg="false" label="Alternate hreflang alias voor Duitse pagina" oneline="true"}
{content block="custom_alternate_hreflang_cn" assign="custom_alternate_hreflang_cn" wysiwyg="false" label="Alternate hreflang alias voor Chinese pagina" oneline="true"}

{content block="countrycode" assign="countrycode" label="Taal van de pagina" oneline=true tab="options"}  

{content_module block="page_header_img" module="GBFilePicker" mode="browser" dir="images/" assign="page_header_img" label="Page header image"}

{if empty($page_header_img)}
  {assign var="page_header_img" value="images/v2/header_img.png"}
{/if}

{content block="page_header_title" label="Page header title" oneline="true" assign="page_header_title"}
{if empty($page_header_title)}
  {if ($page_lang == "nl_NL")}
    {assign var="page_header_title" value="Hét online verzendplatform.<br />Vergelijk tarieven, verzend eenvoudig en bespaar direct"}
  {elseif ($page_lang == "en_US")}
    {assign var="page_header_title" value="Parcel delivery without a hassle; reliable, fast and excellent service!"}
  {elseif ($page_lang == "zh_CN")}
    {assign var="page_header_title" value="包裹会以可靠,快速和最优服务送达"}
  {elseif ($page_lang == "de_DE")}
    {assign var="page_header_title" value="Paketzustellung ohne Probleme; zuverlässig, schnell und mit exzellentem Service!"}
  {/if}
{/if}

{content_module block="icon_image" module="GBFilePicker" mode="browser" dir="images/icon_images/" assign="icon_image" label="Icon image (optioneel)"}


{global_content name='test_open_speed'}

<article class="tpl_vervolg tpl_country_code" data-country-code="{$countrycode}">
  {global_content name='_v2_tpl_header'}

{langify_gcb name="QuoteboxStepsHeader" prefix="_v2_"}
  
  {content_module block="pro_quotation_image" module="GBFilePicker" mode="browser" dir="images/v2/" assign="pro_quotation_image" label="Citaat afbeelding"}
  {content block="pro_quotation_title" label="Citaat titel" oneline="true" assign="pro_quotation_title"}
  {content block="pro_quotation_text" label="Citaat tekst" oneline="true" assign="pro_quotation_text"}
  {content block="pro_quotation_name" label="Citaat naam" oneline="true" assign="pro_quotation_name"}
  
  {if $pro_quotation_title && $pro_quotation_text}
  <aside class="pro_quotation_container container">
    <div class="pro_quotation_block {if !$pro_quotation_image}no_image{/if}">
      {if $pro_quotation_image}
        <img class="pro_quotation_img" src="uploads/{$pro_quotation_image}" alt="{$pro_quotation_title}" />
      {/if}
      <h2 class="title">{$pro_quotation_title}</h2>
      <p class="text">{$pro_quotation_text}</p>
      <p class="name">{$pro_quotation_name}</p>
    </div>
  </aside>
  {/if}
  
  <div class="shipping_form_container container" id="quotebox">
      <div class="row" >
        <div class="col-md-8">
          <app-root step="2" language="{$langcode_short}" id="step2approot" country-to-code="{$countrycode}">  </app-root>
          {*<section class="shipping_form_block clearfix">
            <form id="shipping_form" action="" method="get">
              {global_content name="_v2_quote_box"}
            </form>
          </section>*}
        </div>
       <div class="col-md-4">
 <div class="bg_wrapper">
          <section class="benefits_container">
            <center><h2>{content block="benefits_title" label="Grijs voordelen blok titel" oneline="true"}</h2></center>
           {langify_gcb name="country_benefits" prefix="_v2_"}
<br>

            
           
            
          </section>
        </div>
      </div>
    </div>
  </div>
  
  <div id="sectiondown" class="main_article_container container">
    <article class="row">
      <section class="col-sm-6 col-lg-5">
{if !empty($icon_image)}
        <img class="article_icon" src="{uploads_url}/{$icon_image}" alt="{title}" />
{/if}
        {content label="Content links"}
      </section>
      <section class="col-sm-6 col-lg-7">
        <div id="faq" class="content_right_container">
{langify_gcb name="FAQ" prefix="_v2_"}
                    <div class="action_container">
            {langify_gcb name="vervolg_action_buttons" prefix="_v2_"}
          </div>
        </div>
      </section>
    </article>
  </div>
    {global_content name='_v2_tpl_footer_v2Vervolg'}
</article>
{global_content name='test_close_speed'}

After I enabled "Smarty Caching" and load a page it works all fine (and really fast). However if I load this page incognito all the variables from my template which are used in my "header" global content block pass "null/blank" (e.g. <meta name=description content="")


My header global content block looks like this. Here is the "custom_meta_description" variable for instance being used:

Code: Select all

{cloudflareip}
{babel action="assign"}
{redirect_to_lang_by_ip}

<!DOCTYPE html>
<__html>
<head>


  <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
 

  {updatecss}{assign_shortlang}{process_currentpagealias}

  <title>{if $blogtitle neq ""}{$blogtitle} | {/if}{title} | {sitename}</title>
 
  <meta name="robots" content="all">


 
  <meta property='og:title' content='{title} | {sitename}' />
  {langify_gcb name="header_ogdescription"}
  <meta property='og:url' content='https://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}' />
  
  {metadata}

  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="author" content="" />
  <meta name="copyright" content="Copyright (C) 2018" />



<meta name="keywords" content="{if $custom_meta_keywords neq ""}{$custom_meta_keywords}{else}{langify_gcb name="default_keywords"}{/if}" />


  <meta name="description" content="{if $blog_meta_description neq ""}{$blog_meta_description}{else}{if $custom_meta_description neq ""}{$custom_meta_description}{/if}{/if}" />
  <meta http-equiv="language" content="{$langcode_short}">

  <link rel="shortcut icon" href="{root_url}/favicon.ico">
   


  {if $custom_alternate_hreflang_nl}<link rel="alternate" hreflang="nl_nl" href="{root_url}/nl_NL/{$custom_alternate_hreflang_nl}" />{/if}
  {if $custom_alternate_hreflang_en}<link rel="alternate" hreflang="en_us" href="{root_url}/en_US/{$custom_alternate_hreflang_en}" />{/if}
  {if $custom_alternate_hreflang_de}<link rel="alternate" hreflang="de_de" href="{root_url}/de_DE/{$custom_alternate_hreflang_de}" />{/if}
  {if $custom_alternate_hreflang_cn}<link rel="alternate" hreflang="zh_cn" href="{root_url}/zh_CN/{$custom_alternate_hreflang_cn}" />{/if}

I'm wondering if someone can tell me why these variables (from the template) are not being passed after enabling the "Smarty Caching".

Code: Select all

CMS Version		1.11.7

Any answer is much appreciated, thanks in advance.

Best regards,
Leroy
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Smarty Caching | {content block} variable returns null/b

Post by velden »

I'm not sure it's related to Smarty caching (I never used it) or a variable scope problem.

You could check if it's a scope problem by adding an extra assignment in your template like this:

Code: Select all

{content block="custom_meta_description"  assign="custom_meta_description" wysiwyg="false" label="Meta description" oneline="true" maxlength="160"}
{$custom_meta_description=$custom_meta_description scope=global}
It will change the scope of the variable to global.

Interesting reading: https://cmscanbesimple.org/blog/smarty-scope-examples

And since you're new to Smarty read up on Smarty template inheritance too. It might be much easier than using global content blocks: https://cmscanbesimple.org/blog/the-pow ... gn-manager

Finally: consider upgrading to the latest version of CMSMS
Locked

Return to “CMSMS Core”