Determine if a template is called by include()

Is there a way to determine if a template has been called by ^include()^ or not?

I have the following section in one of my templates and don’t want to export it if the template is called from within another template.

^if($MyHeader!=$MyHeader(prevSibling) & $NotCalledFromIncludeBoolean==True)^
^value($MyString)^
^endif^

  • Attribute $NotCalledFromIncludeBoolean is just an example

The FullPath for the Template is: /Templates/Main/Element

When I use the Include I only want do show contents of “Element” without the header as above.

I understand the idea, but I don’t think that approach will work, but others might. What those ‘others’ might be I can’t guess simply because I don’t know the wider context. Plus ‘include’ can be a slippery term.

Bottom line. No, but with more sight of your template structure the desired outcome is likely possible, i.e. small outcome just via slightly different method.

It might be as simple as cloning the template and using one in an include and on note. Or,
let’s assume your template is called ‘tMyPage’. Now make a template ‘tMyPageHeader’. Th code for the latter is:

^if($MyHeader!=$MyHeader(prevSibling))^
^value($MyString)^
^endif^
^include (this,"tMyPage")^

and in tMyPage remove your ^if^ section. Now notes calling ‘tMyPageHeader’ or tMyPage’ according to whether the extra section ins needed. If your process doesn’t allow that logic, then just explain your logic here and likely we can find a similar work-around.

HTH :slight_smile:

1 Like

You could check if $Path(current)==$Path(this), but in general I think this is getting too fancy.

1 Like

Thanks for your prompt reply. I was considering splitting the templates but wasn’t aware how and that I can use “this”. That should do the work … in both cases.

1 Like