I
I
Ivan Anikin2019-12-05 11:10:20
1C-Bitrix
Ivan Anikin, 2019-12-05 11:10:20

Is it possible to use $APPLICATION->ShowProperty() in component template code?

If everything is clear with the SetPageProperty, SetTitle, etc. functions, they simply will not be executed when the cache is enabled. I don’t fully understand with $APPLICATION->ShowProperty(), it seems like it should put a label that will be filled later with actual data and, therefore, the label should be cached and later filled in.
Now I need to recolor the menu in the header depending on the section. I set in the index.php of the section

$APPLICATION->SetPageProperty('category_style', 'is-red');

well, in the component template
class="top-menu <?$APPLICATION->ShowProperty('category_style', '');?>"

Expecting that, depending on the section, a class is substituted into the cached component. But my insertion with ShowProperty breaks the layout.
Maybe the point is that Bitrix was transferred from win-1251 to utf-8 in our country, and somehow not all files are in utf-8 there? Or is it because ShowProperty cannot be used in the component template?
For some reason, I have a strong confidence that this example was in the exam and it is solved through ShowProperty.
A follow-up question
If you can not use ShowProperty () then which option to use?
1) Of course, I can determine and give a value in the parameter by $APPLICATION->GetCurDir(), but I'm confused that different caches will be created (garbage of course).
2) I can insert a substring like #category_style# and change its value on the
'OnEndBufferContent' event, which confuses me even more.
In general, I want to close this gestald with deferred functions for myself.
How to act in such cases?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yaroslav Alexandrov, 2019-12-05
@alexyarik

There is such a task in exam No. 2 ex2-109 "Change the background in the header"
I already answered a similar question How to display the section property in Bitrix?

I
Ivan Anikin, 2019-12-06
@randomizex

Yaroslav Alexandrov , Evgeny Thank you, the answer is clear. Just sometimes I really want to)
If this call cached a string that was later parsed before output, and its value was changed just before the output (as I thought), I would get the necessary effect. But as I see these ShowProperty(), ShowTitle() functions work differently (they close the current buffer, create another one to display the result of the function, then close it and open a new one) in general, not at all as I thought. Therefore, when the component is cached, this does not happen at all, but the effect is that only part of the component's output is cached after calling ShowProperty ().
Conclusions
1) ShowProperty(), ShowTitle() cannot be used in cached parts of the code.
2) Either we transfer their use to the site template, or to non-cached pages of complex components (such as detail.php section.php news.php, etc.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question