# Assigning {asign} textsnippet containing HTML Content throws SmartyCompilerException

**URL:** <https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814>\
**Category:** Themes & Design\
**Created:** [2. Juli 2018 um 09:20 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814 "2018-07-02T09:20:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrmoree](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrmoree](https://forum.shopware.com/u/mrmoree)\
**Post date:** [2. Juli 2018 um 09:20 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/1 "2018-07-02T09:20:41Z")

</div>

Dear Shopware Community,

i have a Problem with encodings in Shopware assigning a text snippet in the template.

```
{assign var='topBarPromoLinkText' value="{s name="MetaHeaderLeftLinkText__BR2017" namespace="topbarNavigation"}{/s}"}

```

I know that this is no best practice but we need to check the presence of a variable via an if condition so i need to assign it.

```
{if !empty($topBarPromoLink)}
   
      
   
{/if}

```

If i put a Quote in the snippet i get SmartyCompilerException:

Can anyone help me solve this so no matter what the user inserts in to the snippet in the backend the frontend just displays it as normal text!?

```
Error.ERROR: Uncaught Exception SmartyCompilerException: "Syntax Error in template "/var/www/myshop/engine/Shopware/Plugins/Local/Frontend/myshop_AdvancedMenu/Views/frontend/plugins/myshop_advanced_menu/index.tpl" on line 202 "{assign var='topBarPromoLinkText' value='{snippet name=&quot;MetaHeaderLeftLinkText __BR2017&quot; namespace=&quot;myshop_TopbarNavigation&quot; namespace='frontend/plugins/myshop_advanced_menu/index'}{/snippet}'}" - Unexpected "frontend", expected one of: "}" , " " , ATTR" at /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templatecompilerbase.php line 657 {"exception":"Class: SmartyCompilerException Message: Syntax Error in template "/var/www/myshop/engine/Shopware/Plugins/Local/Frontend/myshop_AdvancedMenu/Views/frontend/plugins/myshop_advanced_menu/index.tpl" on line 202 "{assign var='topBarPromoLinkText' value='{snippet name=&quot;MetaHeaderLeftLinkText__ BR2017&quot; namespace=&quot;myshop_TopbarNavigation&quot; namespace='frontend/plugins/myshop_advanced_menu/index'}{/snippet}'}" - Unexpected "frontend", expected one of: "}" , " " , ATTR Stack Trace: #0 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templateparser.php(3144): Smarty_Internal_TemplateCompilerBase->trigger_template_error()\n#1 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templateparser.php(3209): Smarty_Internal_Templateparser->yy_syntax_error(19, 'frontend')\n#2 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_smartytemplatecompiler.php(105): Smarty_Internal_Templateparser->doParse(19, 'frontend')\n#3 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templatecompilerbase.php(192): Smarty_Internal_SmartyTemplateCompiler->doCompile('\\n\\n {* Do we ...')\n#4 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_compile_block.php(197): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template))\n#5 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_compile_block.php(255): Smarty_Internal_Compile_Block::compileChildBlock(Object(Smarty_Internal_SmartyTemplateCompiler), 'frontend_index_...')\n#6 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templatecompilerbase.php(475): Smarty_Internal_Compile_Blockclose->compile(Array, Object(Smarty_Internal_SmartyTemplateCompiler), Array, NULL, NULL)\n#7 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templatecompilerbase.php(249): Smarty_Internal_TemplateCompilerBase->callTagCompiler('blockclose', Array, Array)\n#8 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templateparser.php(2493): Smarty_Internal_TemplateCompilerBase->compileTag('blockclose', Array)\n#9 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templateparser.php(3101): Smarty_Internal_Templateparser->yy_r58()\n#10 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templateparser.php(3201): Smarty_Internal_Templateparser->yy_reduce(58)\n#11 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_smartytemplatecompiler.php(105): Smarty_Internal_Templateparser->doParse(10, '\\n ')\n#12 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templatecompilerbase.php(192): Smarty_Internal_SmartyTemplateCompiler->doCompile('{*! Include Var...')\n#13 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_template.php(187): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Enlight_Template_Default))\n#14 /var/www/myshop/engine/Library/Smarty/sysplugins/smarty_internal_templatebase.php(155): Smarty_Internal_Template->compileTemplateSource()\n#15 /var/www/myshop/engine/Library/Enlight/View/Default.php(274): Smarty_Internal_TemplateBase->fetch()\n#16 /var/www/myshop/engine/Library/Enlight/Controller/Plugins/ViewRenderer/Bootstrap.php(216): Enlight_View_Default->render(Object(Enlight_Template_Default))\n#17 /var/www/myshop/engine/Library/Enlight/Controller/Plugins/ViewRenderer/Bootstrap.php(242): Enlight_Controller_Plugins_ViewRenderer_Bootstrap->renderTemplate(Object(Enlight_Template_Default))\n#18 /var/www/myshop/engine/Library/Enlight/Controller/Plugins/ViewRenderer/Bootstrap.php(136): Enlight_Controller_Plugins_ViewRenderer_Bootstrap->render()\n#19 /var/www/myshop/engine/Library/Enlight/Event/Handler/Default.php(91): Enlight_Controller_Plugins_ViewRenderer_Bootstrap->onPostDispatch(Object(Enlight_Controller_ActionEventArgs))\n#20 /var/www/myshop/engine/Library/Enlight/Event/EventManager.php(214): Enlight_Event_Handler_Default->execute(Object(Enlight_Controller_ActionEventArgs))\n#21 /var/www/myshop/engine/Library/Enlight/Controller/Action.php(201): Enlight_Event_EventManager->notify('Enlight_Control...', Object(Enlight_Controller_ActionEventArgs))\n#22 /var/www/myshop/engine/Library/Enlight/Controller/Dispatcher/Default.php(523): Enlight_Controller_Action->dispatch('indexAction')\n#23 /var/www/myshop/engine/Library/Enlight/Controller/Front.php(223): Enlight_Controller_Dispatcher_Default->dispatch(Object(Enlight_Controller_Request_RequestHttp), Object(Enlight_Controller_Response_ResponseHttp))\n#24 /var/www/myshop/engine/Shopware/Kernel.php(182): Enlight_Controller_Front->dispatch()\n#25 /var/www/myshop/vendor/symfony/http-kernel/HttpCache/HttpCache.php(491): Shopware\\Kernel->handle(Object(Enlight_Controller_Request_RequestHttp), 1, true)\n#26 /var/www/myshop/engine/Shopware/Components/HttpCache/AppCache.php(266): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->forward(Object(Symfony\\Component\\HttpFoundation\\Request), true, NULL)\n#27 /var/www/myshop/vendor/symfony/http-kernel/HttpCache/HttpCache.php(448): Shopware\\Components\\HttpCache\\AppCache->forward(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#28 /var/www/myshop/vendor/symfony/http-kernel/HttpCache/HttpCache.php(344): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->fetch(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#29 /var/www/myshop/engine/Shopware/Components/HttpCache/AppCache.php(187): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->lookup(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#30 /var/www/myshop/vendor/symfony/http-kernel/HttpCache/HttpCache.php(210): Shopware\\Components\\HttpCache\\AppCache->lookup(Object(Symfony\\Component\\HttpFoundation\\Request), true)\n#31 /var/www/myshop/engine/Shopware/Components/HttpCache/AppCache.php(114): Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#32 /var/www/myshop/custom/plugins/DTHttpCache/AppCache.php(86): Shopware\\Components\\HttpCache\\AppCache->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#33 /var/www/myshop/custom/plugins/DTHttpCache/index.php(33): DTHttpCache\\AppCache->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#34 /var/www/myshop/shopware.php(134): include('/var/www/myshop...')\n#35 {main}"} {"url":"/","ip":"127.0.0.1","http_method":"GET","server":"_","referrer":null,"file":"/var/www/myshop/engine/Shopware/Plugins/Local/Frontend/myshop_ExceptionLogging/Bootstrap.php","line":93,"class":"Shopware_Plugins_Frontend_myshop_ExceptionLogging_Bootstrap","function":"onPostDispatchError"}
```

---

<div class="post-metadata">

**Author:** ![simkli](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/simkli/32/13124_2.png) [@simkli](https://forum.shopware.com/u/simkli)\
**Post date:** [2. Juli 2018 um 09:26 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/2 "2018-07-02T09:26:03Z")

</div>

You wrote

```
{assign var='xxx' value="{s name="...}

```

So the parameter named _value_ contains _{s name=_ .  
Everything after the second double quotation mark is intepreted as a next parameter/command/… .

Problem: You can’t use " inside of ". How should smarty know where your parameter ends? It just chooses the next occurence of " as the end marker of the parameter’s value.

Solution: Just use single quotation marks for the second parameter as you did for the first one.

Best regards

---

<div class="post-metadata">

**Author:** ![mrmoree](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrmoree](https://forum.shopware.com/u/mrmoree)\
**Post date:** [2. Juli 2018 um 09:34 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/3 "2018-07-02T09:34:19Z")

</div>

> [@simkli schrieb:](https://forum.shopware.com/profile/16741/simkli "simkli")
> 
> Solution: Just use single quotation marks for the second parameter as you did for the first one.

Thank you very much for your answer. But this does not solve the problem. The code still breaks. I guess it has to do with the {asign} tag… could that be the case?

---

<div class="post-metadata">

**Author:** ![simkli](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/simkli/32/13124_2.png) [@simkli](https://forum.shopware.com/u/simkli)\
**Post date:** [2. Juli 2018 um 09:44 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/4 "2018-07-02T09:44:35Z")

</div>

Can you show us your updated code?

---

<div class="post-metadata">

**Author:** ![mrmoree](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrmoree](https://forum.shopware.com/u/mrmoree)\
**Post date:** [2. Juli 2018 um 09:50 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/5 "2018-07-02T09:50:40Z")

</div>

```
 &nbsp;

{assign var="topBarPromoLinkText" value="{s name='MetaHeaderLeftLinkText__BR2017' namespace='topbarNavigation'}{/s}"}

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![simkli](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/simkli/32/13124_2.png) [@simkli](https://forum.shopware.com/u/simkli)\
**Post date:** [2. Juli 2018 um 09:55 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/6 "2018-07-02T09:55:37Z")

</div>

Does the snippet _MetaHeaderLeftLinkText\_\_BR2017_ contain double quotation marks (")?

If so, I think there’s no easy solution except using PHP and assign the variable there.

Best regards

---

<div class="post-metadata">

**Author:** ![mrmoree](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrmoree](https://forum.shopware.com/u/mrmoree)\
**Post date:** [2. Juli 2018 um 10:04 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/7 "2018-07-02T10:04:04Z")

</div>

> [@simkli schrieb:](https://forum.shopware.com/profile/16741/simkli "simkli")
> 
> Does the snippet _MetaHeaderLeftLinkText\_\_BR2017_ contain double quotation marks (")?
> 
> If so, I think there’s no easy solution except using PHP and assign the variable there.
> 
> Best regards

yes thats true. it contains double quotes. we must asume that the editor puts in quotes.

---

<div class="post-metadata">

**Author:** ![simkli](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/simkli/32/13124_2.png) [@simkli](https://forum.shopware.com/u/simkli)\
**Post date:** [2. Juli 2018 um 10:06 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/8 "2018-07-02T10:06:42Z")

</div>

If you tell us what you want to achieve, maybe we can find a different solution?

Why do you have to assign it to a variable anyways? Can’t you just use the snippet directly?

Best regards

---

<div class="post-metadata">

**Author:** ![mrmoree](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrmoree](https://forum.shopware.com/u/mrmoree)\
**Post date:** [2. Juli 2018 um 10:22 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/9 "2018-07-02T10:22:02Z")

</div>

> [@simkli schrieb:](https://forum.shopware.com/profile/16741/simkli "simkli")
> 
> If you tell us what you want to achieve, maybe we can find a different solution?
> 
> Why do you have to assign it to a variable anyways? Can’t you just use the snippet directly?
> 
> Best regards

Ok, i need to asign the variable to the view because we use an if condition to check which fields are filled to decide what code to render.

If there was another way to check empty of a snippet directly, maybe that could help.&nbsp;

```
{if !empty($topBarPromoImageLink)}
   {if !empty($topBarPromoLink)}
      
         
      
   {else}
      
   {/if}
{elseif !empty($topBarPromoLinkText)}
   {if !empty($topBarPromoLink)}
      
         {$topBarPromoLinkText}
      
   {else}
      {$topBarPromoLinkText}
   {/if}
{/if}

```

Excuse the wrong formatting but the code element does it automatically here.

&nbsp;

Best regards,

Oliver

---

<div class="post-metadata">

**Author:** ![mrmoree](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mrmoree](https://forum.shopware.com/u/mrmoree)\
**Post date:** [2. Juli 2018 um 13:35 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/10 "2018-07-02T13:35:45Z")

</div>

anyone an idea?

---

<div class="post-metadata">

**Author:** ![simkli](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/simkli/32/13124_2.png) [@simkli](https://forum.shopware.com/u/simkli)\
**Post date:** [3. Juli 2018 um 06:10 UTC](https://forum.shopware.com/t/assigning-asign-textsnippet-containing-html-content-throws-smartycompilerexception/53814/11 "2018-07-03T06:10:36Z")

</div>

I’d suggest using a plugin like this:  
(Comments are included)

```
 'onPostDispatch'

            // 2. Maybe you also need the variable inside a widget module
            // if so uncomment the following line
            //'Enlight_Controller_Action_PostDispatchSecure_Frontend' => 'onPostDispatch'
        ];
    }

    /**
     * The event listener function 
     */
    public function onPostDispatch(\Enlight_Controller_ActionEventArgs $args)
    {
        /** @var \Enlight_Controller_Action $controller */
        $controller = $args->get('subject');
        $view = $controller->View(); // 3. get the view object

        $snippets = Shopware()->Container()->get('snippets'); // 4. get the snippets object from the DI

        // 5. select your snippet
        $metaHeaderLeftLinkText = $snippets->getNamespace('topbarNavigation')->get('MetaHeaderLeftLinkText__BR2017');

        // 6. Assign it a a tpl variable called topBarPromoLinkText
        $view->assign('topBarPromoLinkText', $metaHeaderLeftLinkText);
    }
}

```

Just put this file at custom/plugins/MrMoreePlugin/MrMoreePlugin.php , install it, activate it and clear the cache. Then you should have a new frontend variable called topBarPromoLinkText containing the snippets text. This code is untested.

[https://developers.shopware.com/developers-guide/plugin-quick-start](https://developers.shopware.com/developers-guide/plugin-quick-start)

Best regards
