A
A
alexander_chn2018-04-04 18:45:11
1C-Bitrix
alexander_chn, 2018-04-04 18:45:11

How to insert a variable into meta tags in Bitrix?

Hello! The crux of the matter is this. There is a meta tag, for example $APPLICATION->SetPageProperty and you need to insert a variable there, i.e. the meta tag changes depending on the parameters. Now I implemented it like this:

$APPLICATION->SetPageProperty("title", "$cur_city[$poddomen]");

$cur_city[$subdomen] is an array that substitutes the desired value. But the problem is that when you change some other SEO property through the admin panel, the system saves this line in the form:
$APPLICATION->SetPageProperty("title", "\$cur_city[\$poddomen]");

and, accordingly, the code is no longer executed, but simply statically assigned to $cur_city[\$poddomen].
Can this be fixed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
I'm Yoda, 2018-04-04
@Anadi

Try like this

$APPLICATION->SetPageProperty("title", $cur_city[$poddomen]);

A
Andrey Nikolaev, 2018-04-05
@gromdron

And those options won't work.
You can try the universal syntax of course, but I don't think it works in this part.
As for the task itself, it is usually done like this:
1) We develop the component, for example, custo:header.meta
2) In the component, we check the conditions (for example, through GetPageProperty ), as well as additional. options.
If in all respects you need to replace - use the design Lorem Ipsum . If you don't need to replace, skip.
Important question: Why do you need to do this?
In Bitrix24 , you cannot deprive the user of the ability to override specific tags on pages.
It's better to do all this in one place than to look for where $cur_city comes from and what $subdomen is.
And besides, it will be necessary to go through each page and see if there are any errors on others, and so - 1 component that holistically closes this task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question