logo
Home XtGem- Templates- XtScript- bottom
Switch the headtags for specified pages
This script goes in your _headtags file
The entries in $alt_headtags_pages should be just enough of the url to uniquely identify a single page a folder of pages or even a subdomain
Use a pipe symbol | to mark the end of an entry
Using {{...}} the entries can be on separate lines
The : are just padding for the loop
Note: subdomains should have an additional entry as a folder of the main site
This is because
<xt:url>
will not return a subdomain for http://subdomain.site.com without a page specified in the url ie: http://subdomain.site.com/index
Show in textarea
<!--parser:xtscript-->
# Alt headtags pages data variable
var $alt_headtags_pages = {{:
folder/page|
folder/|
sub.domain.com|
domain.com/sub|
test=1|
:}}

# Variables
var $this_page = <xt:url>
var $entry_offset = 1

# Main loop
@loop 

# Find the end of the current entry
var $entry_end = call strpos $haystack=$alt_headtags_pages;$needle=|;$offset=$entry_offset

# No more entries left so use normal headtags
if  not $entry_end

# Output the normal headtags and exit
print {{ Normal Headtags }}
goto @end_alt_headtags
endif

# Get the next entry
var $needle = call substr $val=$alt_headtags_pages;$start=$entry_offset;$length=($entry_end-$entry_offset)
var $needle = call trim $val=$needle

# Check if the entry matches the current url
var $alt_headtags = call strpos $haystack=$this_page;$needle=$needle

# Entry matches so use the alternative headtags
if $alt_headtags

# Output the alternative headtags and exit
print {{ Alternative Headtags }}
goto @end_alt_headtags
endif


# No match for this entry in the current url 
# so move the offset pointer to the start of the next entry
var $entry_offset = ($entry_end+1)

# Loop back
goto @loop

@end_alt_headtags
<!--/parser:xtscript-->
Show in textarea
Reload
Normal Headtags
Click reload to reset
test alt headtags
Powered by XtGem
About us Contact Forum topÂ