Accessing html.tpl.php variables from page.tpl.php - drupal

Greeting,
I am stuck with accessing $scripts variable of html.tpl.php in page.tpl.php, how to access the variable?
I am using Drupal 7
Please Help.
Thanks in Advance.

In order to alter the page's scripts, take a look at implementing hook_js_alter() in a custom module. That will allow you to perform the necessary alterations without messing with the rendered output. Further info here.

You must send explicity the variable you want to the template you want, template variables are template specific, there's no inheritance or another clean way.
The clean way is send what you need to specific template or implement a hook if it exists and does what you want.
Finally, in this case, I think you have to decide which files are loaded when hook_js_alter is called as suggested jamix.

Related

Trying to override templates in FOSUserBundle, but having no effect

I'm trying to modify the skin of the register.html.twig template found in FOSUserBundle/Resources/views/Registration/register.html.twig.
I've basically followed the instructions in the documentation down to a T.
Like it told to do so, I created /app/Resources/views/FOSUserBundle/views/Registration/register.html.twig.
Cleared the cache (and browser cache just to be sure)
NO effect! I've put a blank file in register.html.twig, but no matter what I put there, when I go to /register/, I still see the default template.
Yep, these things happen all the time.
It should be:
/app/Resources/FOSUserBundle/views/Registration/register.html.twig
Reference

Parsing page data into sidebar - wordpress

What would be the proper procedure for accessing the current page html data and picking up all of a certain tag and throwing them into the sidebar as links?
I'm not sure your proficiency with php, but I'll give you and overview of what you'd probably want to do.
First, you need the HTML. I'm assuming you're running this on a page (in a page.php file or single.php file, or similar), this means that you have access to the global variable $post, which contains the html of the page in it. To access it you can use the helper function get_the_content(), this returns the html being displayed.
Next you need to parse through this to get the h2 tags. A simple regex can handle this, something like <h2[^>]*>(.*)</h2>. It's important to remember that this regex is very picky, so format your html correctly, no multiline h2s.
So now you have the html, and have parsed it with a regex to get the h2s. Now you need to generate the list from the results, and prepend it to the top of the content of the page. There are a ton of ways to do this, the easiest being just running the code in the right spot in the template file.
Of course there are probably better ways of doing this, I'd recommend you look at say a FAQ plugin (if that's what this is for), or do the lists manually (as this system can be broken), or possibly use a custom post type; but for your question, that's how I'd do it.

preprocess_views_view not getting called

Drupal 7,
Views,
Bootstrap theme sub theme in use
I have a views-view-table.tpl.php file in my sub theme and I am trying to preprocess some of the variables sent to this tpl. I created a function bootstrap_preprocess_views_view(&$vars) in my template.php and it is not getting called when I visit one of my views pages. Why would this be? Other preprocess functions are getting called from the same template file. I have tried flushing the cache.
function bootstrap_preprocess_views_view(&$vars) {
dsm($vars);
dsm("aaaa");
die;
}
Adam,
I'm assume you've tried all the regular things like clearing your cache, etc before expecting to see the change.
If yes, perhaps this old Drupal issue may be affecting your function: http://drupal.org/node/258089 (since your syntax looks fine).
Do you actually have a corresponding template file in your sub-theme? If you place one in there (even just by copying and pasting the default one from the views module), does it solve your issue?
Let us know!

Drupal views add form to add record

I have some view which lists my module table entries.
What is the most elegant way to attach a form below the view to add record?
Waht I am trying to do know is:
I created dedicated form in my module:
function my_module_form_add_record($form_state) {
form fields.....
}
I added to the view theme file:
$add_form = drupal_get_form('my_module_form_add_record');
print $add_form;
But I do not like this solution for at least 2 reasons:
I does not work ...
2. Even if it worked - it is depended on the theme file! So if I change the theme - functionality is crashed.
I would like to find more elegant solution to attach form from custom module to the view.
I know of the existence of the "Views Attach" module but it has no option of adding custom forms.
I know also of the existence of the Views Embedded form (and I am usig it) but it is only useful if you want to add form to the every row.
Seems the must be some solution to add record from the view page!
Thanks you for help.
you could use hook_views_pre_render:
This hook is called right before the render process. The query has been executed, and the pre_render() phase has already happened for handlers, so all data should be available.
Adding output to the view can be accomplished by placing text on $view->attachment_before and $view->attachment_after. Altering the content can be achieved by editing the items of $view->result.

How does one inject variables into page templates from a custom Drupal module?

We've created a custom module for organizing and publishing our newsletter content.
The issue I'm running into now -- and I'm new to theming and Drupal module development, so it could just be a knowledge issue as opposed to a Drupal issue -- is how to get each newsletter themed.
At this point the URL structure of our newsletter will be:
/newsletters/{newsletter-name}/{edition-name}/{issue-date} which means that we can create template files in our theme using filenames like page-newsletters-{newsletter-name}-{edition-name}.tpl.php, which is great. The one issue I'm running into is that all of the content comes through in the $content variable of the theme. I'd like to have it come through as different variables (so that I can, inside the theme, place certain content in certain areas.)
Is there a proper way for doing this?
Edit: To answer some questions: The issue is a node (there are issue, edition and newsletter nodes) and the path is being set using hook_menu with wildcards and a router.
The best answer I could find was to add a check inside of phptemplate_preprocess_page to send the vars back to the module and have them be updated.
Like so:
function phptemplate_preprocess_page(&$vars) {
if (module_exists('test_module')) {
_test_module_injector($vars);
}
}
then in my test_module.module file I created this function:
function _test_module_injector(&$vars) {
$vars[] = call_to_other_functions_to_load_vars();
}
It seemed to work. I wish there was a way to do this without having to touch the theme's template.php file, but otherwise this works well.
If there were better documentation for template preprocess functions, Drupal would be a lot more accessible - as it is, you need to piece together the information from a lot of different explanations. One place to start is here:
http://drupal.org/node/223430
but if you take the time to work through the tutorial below, you'll find you can do most things:
http://11heavens.com/theming-the-contact-form-in-Drupal-6
This is an old post, and the OP's issues seems to have been solved.
However, just for others finding this through Google (or otherwise):
Install the 'Devel' module: http://drupal.org/project/devel
Also the 'Devel Themer' module: http://drupal.org/project/devel_themer
Use Devel Themer to go through the $content variable and find what you need to pull out.
There are a bunch of Devel/Themer docs/tuts out there, but its usage is pretty straightforward. Note, though, that some stuff in there will need to be sanitized before printing in the theme.
The suggestion to show the node as a View and then modifying the view templates sounds pretty crazy, though it'll work.

Resources