Ad

October Cms Linking Another Page Into A Page

- 1 answer

I am trying to add link to static page

 `<a href='{{ "administer/catalog-items_item"|page({ item_id: item.id })  }}'>test             
   </a>`

when I click on test it clicked URL its not working correctly, it seems twig is not parsing static page content. or more likely static page is not using twig engine to parse its code.

is there any way to work this out? how can I add dynamic link generated by twig to static page content.

Ad

Answer

You can not add twig markup into the static page content.

However if you want ot use twig markup you can use it using snippets.

Let me show you, how you can add that dynamic link using snippet.

  1. Create snippet
  2. Add snippet to the your static page

1. Create snippet

enter image description here

OR just use code and add it

file : /themes/your_theme/partials/static-snippet.htm

description = "test snippet"

[viewBag]
snippetCode = "test-snippet"
snippetName = "Test Snippet"
==
<a href={{ "ajax"|page }}> click me </a>

Note : please change code according to your need. <a href='{{"administer/catalog-items_item"|page({ item_id: item.id }) }}'>test</a>

for your item id you need to make variable which id you want to show in snippet. or from partial add component and get it from there there.

2. Add snippet to the your static page

enter image description here

OR just use code and add it

file : /themes/your_theme/content/static-pages/static-page.htm

enter image description here

OR just use code and add it

file : /themes/your_theme/content/static-pages/static-page.htm

[viewBag]
title = "static-page"
url = "/static-page"
is_hidden = 0
navigation_hidden = 0
==
<figure data-snippet="test-snippet">&nbsp;</figure>

Note : here you just need to use <figure data-snippet="test-snippet">&nbsp;</figure> and paste it where you need to show link.

#Dynamic Links using property

1. Add property

enter image description here

Code

description = "test snippet"

[viewBag]
snippetCode = "test-snippet"
snippetName = "Test Snippet"
snippetProperties[itemId][title] = "Item Id"
snippetProperties[itemId][type] = "string"
snippetProperties[itemId][default] = ""
snippetProperties[itemId][options][] = ""
==
<a href={{ "param"|page({ id: itemId }) }}> click me {{itemId}} </a>

2. Click ok snippet and add desired value. and then again add new snippet and add new value as much as you like

enter image description here

Code

[viewBag]
title = "static-page"
url = "/static-page"
is_hidden = 0
navigation_hidden = 0
==
<figure data-inspector-id="inspectorid-447952244549" data-property-itemid="10" data-snippet="test-snippet">&nbsp;</figure>

if any doubt please comment.

Ad
source: stackoverflow.com
Ad