There are possibly a few options here, and none of them feel that 'neat'...
1) Your MacroPartial could include a comment eg:
<!-- macro is here -->
and then instead of writing out the contentText property you could read it into a variable first, and look for this comment in the content eg
@{
var sliderUsed = false;
var contentText = Model.Content.GetVortoValue("contentText");
sliderUsed = contentText.Contains("<!-- macro is here -->");
}
@Html.Raw(contentText)
2) Or you could have a checkbox on your document type called 'sliderUsed', and use the contentservice save event, to read the contentText property at the point of saving, and check the checkbox if the macro is contained in the contentText. you'd then use this checkbox in your view to determine whether to run the second menu... (or editors could manually check this)
3) Write out the InlineSlider macro after the content anyway, but inside a div, and use client side javascript to determine whether the main content text contains the carousel html from the macro, and only show the secondary carousel if there isn't any.
How to detect if macro is inserted via RTE
Hello,
I built a text page with image gallery. The editor can add gallery inside text content via insert macro.
In template code I want to check if the editor has added the gallery via RTE, and run the macro if not added before.
I tried to add a variable and then change the variable via added macro, but it didn't work.
Template view is something like
And the macro partial is something like
How can i detect if user is inserted macro into RTE, and run if not added?
Any ideas?
Hi Osman
There are possibly a few options here, and none of them feel that 'neat'...
1) Your MacroPartial could include a comment eg:
and then instead of writing out the contentText property you could read it into a variable first, and look for this comment in the content eg
2) Or you could have a checkbox on your document type called 'sliderUsed', and use the contentservice save event, to read the contentText property at the point of saving, and check the checkbox if the macro is contained in the contentText. you'd then use this checkbox in your view to determine whether to run the second menu... (or editors could manually check this)
3) Write out the InlineSlider macro after the content anyway, but inside a div, and use client side javascript to determine whether the main content text contains the carousel html from the macro, and only show the secondary carousel if there isn't any.
regards
Marc
Hi Marc,
I solved problem with Session variables.
If macro is used inline a session variable is created.
After the RTE content razor check if the session variable exists and calls macro if never used before.
Thank you.
is working on a reply...