Can layout hooks be used to echo a script?

dh

Member
In version 9 Monterosso (not installed yet, so I'm not including version info) can layout hooks such as custom_footer_1 or _2 be used to echo a script, such as those used by Google ads?

Is the way to do this to wrap the entire existing <script> ... </script> block in an echo ' ' statement just like echoing HTML in the documentation?

I currently have implemented Google scripts by customizing footer.php and I would much prefer to have them in the custom_functions.php file that I can preserve across future upgrades. Just checking that this is possible before I begin the v. 8 to v. 9 upgrade.

Thank you. Congrats on what looks like an excellent new major version, with many features I have wanted.
 

eugenio

Administrator
Staff member
Hello and thanks for the appreciation!
Sure, the idea of layout hooks was mainly to use them to run simple echo statements containing HTML code (even if you can run any PHP code).

So in your hook function you can just write something like:

echo '<script>...........</script>';

Best,
 

dh

Member
OK, so before messing with a Google script, I'm trying a very simple script first, just changing the web page element title from "DaDaBIK" in order to avoid having to mess with header.php as I usually do. It looked easiest to me to choose the lowest-down layout hook, footer_2, but this hook in custom_functions.php produces a white screen in Safari and a 500 error in Vivaldi:

[pre]
$hooks['custom_footer_2'] = 'dadabik_change_title';

function dadabik_change_title()

{

echo '<script>document.title="New Title Here";</script>'

}
[/pre]


Can you see anything obviously wrong with that? I'm running this instance in public_user mode (which I LOVE, by the way... almost exactly what I needed). Of course, this could just be my ignorance in JavaScript, so if you see a stupid mistake, please point it out to me.

Thanks.









You are using DaDaBIK version 9.0-Monterosso enterprise, installed on 07-06-2018 (installation code: 1301759e8f80ba9589), the latest version of DaDaBIK is released on --

You are not running the last release of DaDaBIK, the release you are running might have bugs and security holes, see the official change log for further information. You can upgrade DaDaBIK here.

PHP Version: 7.2.7

mysql version: 5.6.39

Web server: Apache

Client: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.183 Safari/537.36 Vivaldi/1.96.1147.52
 

dh

Member
Sorry, one more question that I can't see addressed in the docs.

Understanding the constraint that there's only one function allowed per hook, how are multiple hooks entered in the custom_functions.php file?

Is there any separator required between hook/function groupings? Or are all the hook statements grouped together (separator?), followed by the distinct function definitions one after another (separator?).

Maybe easier than answering that in words is can you provide an example of a file with multiple hooks each with one function for me to model? Thank you again.
 

eugenio

Administrator
Staff member
Hello,
you can just add all your hook functions in custom_functions.php, no particular order is required.

Best,
 
Top