Search

Hi Guys,

I have a quick question. I have created a new section called Advertisements with it’s own navigation item in my back end with two fields, text line for the Title and a text area to input the code I get from Google Ad manager.

I then wanted to create a new data source called Header Banner that pulls the content of the text area that i’ve input the code into. I want to then add this to my template in the </head> area.

I know normally I could just plug the code in but I am often making changes and this is a good chance for me to learn a bit more about symphony and xslt. Can someone point me to the right process or what I need to do?

Try following the Hello World Tutorial. That’ll give you a basic sense of how you get content from the back end onto your front-end pages.

Do you actually need to input all the code from Google Ad manager?

I have not used Google Ads for a long time, but I guess this is the code you want to put in your <head> area:

&lt;script type="text/javascript">
    <!--
    google_ad_client = "pub-91578019823752";
    google_ad_slot = "124525163";
    google_ad_width = 336;
    google_ad_height = 280;
    -->
&lt;/script>

Now, you could also create 4 text fields named client, slot, width and height instead of the text area. In these fields you would put in the information necessary.

Now, create a datasource pulling the desired Google Ad named advertisements. I assume that you need the latest one, so let’s sort by System Id, keep sort order descending, and show a maximum of 1 results (assuming you want to display one advertisement). Included elements should be client, slot, width and height (perhaps title if you want to do something with this).

This will return some XML similar to this (but with handles):

<advertisements>
    <section id="15" handle="advertisements">Adventerisements</section>
    <entry id="327">
        <client handle="pub-91578019823752">pub-91578019823752</client>
        <slot handle="124525163">124525163</slot>
        <width handle="336">336</width>
        <height handle="280">280</handle>
    </entry>
</advertisements>

Then, create an XSLT template for the code in the head:

<xsl:template name="advertisements">
    &lt;script type="text/javascript">
        <xsl:comment>
        google_ad_client = "<xsl:value-of select="//data/advertisements/entry/client" />";
        google_ad_slot = "<xsl:value-of select="//data/advertisements/entry/slot" />";
        google_ad_width = <xsl:value-of select="//data/advertisements/entry/width" />;
        google_ad_height = <xsl:value-of select="//data/advertisements/entry/height" />;
        </xsl:comment>
    &lt;/script>
</xsl:template>

You can put this code in your master.xsl or create a seperate .xsl file and include this in your master.xsl.

Now, also in master.xsl within the <head> area, put in this line:

<xsl:call-template name="advertisements" />

Now, I haven’t tested this code at all but it should give you some pointers. Good luck!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details