- Posts: 404
COMMUNITY FORUM
Extra Field in itme.php template override?
- Odin Mayland
- Topic Author
- Offline
- Platinum Member
Less
More
4 years 6 months ago - 4 years 6 months ago #175495
by Odin Mayland
SOLVED: Extra Field in itme.php template override? was created by Odin Mayland
I want to allow an editor to paste in the Google Ad Manager code into and extrafield which gets added to the HEAD.
When I try the following I get (0 - Call to a member function addScriptDeclaration() on null)
<?php
$doc->addScriptDeclaration('<?php echo $this->item->extraFields->HEADCODE->value ;?>');
?>
This is the code in the EF:
<script async src="securepubads.g.doubleclick.net/tag/js/gpt.js">
<script>
window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
googletag.defineSlot(\'/21745156823/i10_sidebar_1\', [300, 250], \'div-gpt-ad-1587755337037-0\').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
If this is possible, can you help me with the correct method to accomplish this?
When I try the following I get (0 - Call to a member function addScriptDeclaration() on null)
<?php
$doc->addScriptDeclaration('<?php echo $this->item->extraFields->HEADCODE->value ;?>');
?>
This is the code in the EF:
<script async src="securepubads.g.doubleclick.net/tag/js/gpt.js">
<script>
window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
googletag.defineSlot(\'/21745156823/i10_sidebar_1\', [300, 250], \'div-gpt-ad-1587755337037-0\').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
If this is possible, can you help me with the correct method to accomplish this?
Last edit: 4 years 6 months ago by Odin Mayland.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
4 years 6 months ago #175501
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Extra Field in itme.php template override?
If you want to output the entire Google snippet in the <head>, you should use "addCustomTag" instead. You also need to set $doc before that and cleanup the invalid PHP tags in PHP. So it should be:
More on adding JS/CSS in the <head> here: docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page
$doc = Factory::getDocument();
$doc->addCustomTag($this->item->extraFields->HEADCODE->value);
More on adding JS/CSS in the <head> here: docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Odin Mayland
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 404
4 years 6 months ago #175514
by Odin Mayland
Replied by Odin Mayland on topic Extra Field in itme.php template override?
Awesome thanks! I made it JFactory instead and it works great!
Please Log in or Create an account to join the conversation.
- Odin Mayland
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 404
4 years 6 months ago #175515
by Odin Mayland
Replied by Odin Mayland on topic Extra Field in itme.php template override?
I can create a separate post if you want but this is also part of this custom setup.
When I put:
{source}<?php echo $this->item->extraFields->adcode->value ;?>{/source}
into a the content area of an item, I get:
0 - Using $this when not in object context
Is there a solution for this?
www.icd10monitor.com/google-ads-test?google_preview=Xnc7DpJNPq0YnpWc9QUwnrHR_AWIAYCAgKDnoY28gwE&iu=21745156823&gdfp_req=1&lineItemId=5311773287&creativeId=138304104308
When I put:
{source}<?php echo $this->item->extraFields->adcode->value ;?>{/source}
into a the content area of an item, I get:
0 - Using $this when not in object context
Is there a solution for this?
www.icd10monitor.com/google-ads-test?google_preview=Xnc7DpJNPq0YnpWc9QUwnrHR_AWIAYCAgKDnoY28gwE&iu=21745156823&gdfp_req=1&lineItemId=5311773287&creativeId=138304104308
Please Log in or Create an account to join the conversation.
- Odin Mayland
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 404
4 years 6 months ago #175527
by Odin Mayland
Replied by Odin Mayland on topic Extra Field in itme.php template override?
I was able to solve this by using RegularLabs Articles Anywhere and this code: {article type="k2"}[extra-22]{/article}
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
4 years 6 months ago #175540
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Extra Field in itme.php template override?
Great :)
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.