Create a variable that stores a url string in Kentico

Jacob Mallach asked on September 9, 2021 16:58

Hello,

We have a url that points to an academic catalog. This url changes every year and is used repeatedly across many different webpages (100+) on our site. I'd like to create/set a variable/macro? that allows our authors to use and in turn eliminate the worry about needing to manually update this url every year.

I'm needing a solution that allows authors to manually call or insert the variable into the paragraph text of a wysiwyg widget.

Something like this. ex.) <a href="{{current catalog url}}">academic catalog</a>

Appreciate your help/suggestions.

Thanks!

Correct Answer

Dmitry Bastron answered on September 10, 2021 06:56

Hi Jacob,

Although it's not a 100% direct usage of the Localization app, however, we are using it as well in similar cases. When you add localization string, say CatalogUrl, you would be able to use it in text fields / web parts / transformations /etc using macro expression like this {$CatalogUrl$}. Refer to this docs article.

1 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on September 9, 2021 22:20

Hi,

is this a Portal Engine or MVC site?


You probably discussed this with your client, but would just creating a specific handler for it work?

Like www.yoursite.com/specialservice/getlatestcatalog where you create a handler that based on time/a setting/phase of the moon/etc. return something else?

if the url is important you could also make the handler to always redirect you to the latest url?

0 votesVote for this answer Mark as a Correct answer

Jacob Mallach answered on September 9, 2021 22:25

Hi David,

Maybe - I'm not familiar with handlers? This is a portal site i.e., Kentico 12. Also, the changing url is a third party.

Thanks!

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on September 9, 2021 22:31

well the handler has actually nothing to do with Kentico.

Probably a dozen more/better blogs and websites on the internet explaining it, but this could get you started:

https://www.c-sharpcorner.com/uploadfile/37db1d/create-your-first-http-handler-in-Asp-Net-3-5/

You'll basically create some code that could still interact with Kentico API (for e.g. getting something from settings) and doesn't return actual page content but just redirects you to somewhere.

0 votesVote for this answer Mark as a Correct answer

Jacob Mallach answered on September 9, 2021 23:05 (last edited on September 10, 2021 00:10)

Hi David,

Thanks for sharing that. I think we'd prefer something that could be managed through the Kentico admin. I had been looking at the Configuration-->Localization menu item in the Kentico admin, that allows you to store a string. Is it possible to use the localization key and return the stored value using a macro from inside the text editor? Or something to that extent?

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on September 10, 2021 09:10

Although you can using macros, letting them being added in Rich Texts by editors might be hard for some them. Also you should make sure everywhere the content will be used macro's are resolved!

2 votesVote for this answer Mark as a Correct answer

Jacob Mallach answered on September 10, 2021 15:43

@Dmitry - Yes, it works. Thank you a bunch!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.