How to have #Where #Restrict #Code templates to specific #Embed(s)

The template command #Where which works with the #Code template command is supposed to limit where the #Code template can be used.

#Where(%SomeEmbedPoint)
#Where(%SomeEmbedPoint, %AnotherEmbedPoint,%AndAnotherEmbedPoint)
#Where(%AStartRangeOfEmbedPoints..%EndOfARangeOfEmbedPoints)

But I cant seem to get it to work and I cant find any examples in the shipping templates.

Any ideas if this works?

TIA

Not in front of my dev box, but wouldn’t that be #AT(%SomeEmbedPoint),WHERE(Condition)?

=

So no short hand for the csv embed points or the range of embed points?

I just wanted to check if I was doing something wrong.

Edit.
So the crux of the problem is there is no way of adding a code template to a specific embed in the embed editor and whilst the #At(%EmbedPoint) can force code to be generated at the correct embed, having a code template on the wrong embed but generating code at the right embed can cause confusion when looking at this in the embed editor.

I’ve tried various things inside #Restrict/#EndRestrict, but there’s no way of getting the hilighted embed in the embed editor.

So I’ve opted to use a procedure #Extension to add comments/#Prompts and new embeds to the specific parent embed which has the HIDE attribute for a work around.

Its not ideal but it works.

The only other idea I havent tried is rehashing the embed info template, theres a template called ProcBind.tpw with a group which looks promising.
#Group(%ProcedureAutoBindShowWrongEmbed)

Edit2.
I think I have found a hack using error to get %EmbedID and then put it into #Group with a return string that tells the user to just click OK and then I can get the hilighted embed point out of the embed editor. And then I can get #Restrict to work :grinning:

Didnt need to use the #Error hack to get the %EmbedID. It seems when my dev computer was online %EmbedID wasnt working, but now its offline it is, so this code below works as a replacement for #Where()

Single Embed Point:

#Code(CodeTemplateName,'Description for Code Template Name')
#Restrict,Where(%EmbedID = '%SomeEmbedIdentifier'))
#Accept
#EndRestrict

Or it can be expanded to a group to gain a bit more of the functionality of #Where()

Multiple Embed points:

#Code(CodeTemplateName,'Description for Code Template Name')
#Restrict,Where(%grpWhere(%SomeEmbedIdentifier,%AnotherEmbed,%AndAnother))
#Accept
#EndRestrict

#Group(%grpWhere,%p1='',%p2='',%p3='',..%p39='',%p40='')
#IF(%EmbedID = %p1)
#Return %True
#ElsIF(%EmbedID = %p2)
#Return %True
#ElsIF(%EmbedID = %p3)
#Return %True
..
#ElsIF(%EmbedID = %p39)
#Return %True
#ElsIF(%EmbedID = %p40)
#Return %True
#Else
#Return %False
#End

Havent figured out how I can loop through all the %EmbedID’s in order though.

I seem to recall Windows only allows upto 32 params, but I’ve got 40 params declared in the group without complaint.

Anyway if you select an embed in the embed editor and then click Insert to select a template, #Code templates which can work on the hilighted embed will now appear in the list.

This is instead of showing all #Code templates which were not for the hilighted embed in the embed editor.

Done this as a separate post to declutter.

The shipping Web Builder templates have the below code that uses #WHERE via a #RESTRICT #Call to a Group

wbcode.tpw 39  DynamicHTML  #CODE         #CALL(%ValidateHtmlEmbedPoint)
wbcode.tpw 48  StaticHTML   #CODE         #CALL(%ValidateHtmlEmbedPoint)
wbgrp.tpw  785 %ValidateHtmlEmbedPoint    #GROUP (%ValidateHtmlEmbedPoint)
#CODE (StaticHTML, 'Insert static HTML'),DESCRIPTION('Static HTML: ' & %FirstLine(%StaticHTMLText)),HLP('~ICCodeStaticHTML')
#RESTRICT
  #CALL(%ValidateHtmlEmbedPoint)
#END
#BOXED ('HTML to insert')
  #PROMPT ('', TEXT), %StaticHTMLText,AT(,,,200)
#END
#INSERT (%GenerateLiteralHtml, %StaticHTMLText)
#GROUP (%ValidateHtmlEmbedPoint)
#WHERE (%WebBeforeControl, %WebAfterControl)
#WHERE (%WebTitleContentsVirtual, %WebBodyHeaderVirtual, %WebBodyFooterVirtual)
#WHERE (%WebMetaTagsVirtual, %WebHeadFooterVirtual, %WebBeforeBodyVirtual)
#WHERE (%WebFormHeaderVirtual, %WebFormFooterVirtual, %WebHtmlFooterVirtual)
#REJECT

What version of Clarion are you seeing these Web Builder templates in?

Nothing is showing up in my version of C11, but what I’ve got working, works in C6 though.

That code was from 11.0 but they have shipped since at least 9.0.

I think to have Web Builder installed during the Setup you have tick a box and probably choose a custom install to see that box. I don’t use WB but often find some interesting stuff in the code. For awhile new features were added to implement WB.