Creating new section and data source
This is an open discussion with 2 replies, filed under General.
Search
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:
<script type="text/javascript"> <!-- google_ad_client = "pub-91578019823752"; google_ad_slot = "124525163"; google_ad_width = 336; google_ad_height = 280; --> </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"> <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> </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.
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?