Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal: Passing custom variable from custom module to my template
    primarykey
    data
    text
    <p>I realize this question has been asked, but I either simply don't understand or the previous answers don't apply (or I don't understand how to apply them) to my circumstance. Here goes:</p> <p>I have a custom module named: </p> <p>"my_module" in /sites/all/modules/custom/my_module</p> <p>I have a module file: </p> <p>/sites/all/modules/custom/my_module/my_module.module</p> <p>I have a page template name "page-mypage" which is NOT in my module:</p> <p>/sites/all/themes/<strong>mytheme/pages</strong>/page-mypath-mypage.tpl.php</p> <p>I made the hook menu for this:</p> <pre><code>$items['mypath/mypage'] = array( 'title' =&gt; 'My Page!', 'page callback' =&gt; 'my_module_mypage', 'page arguments' =&gt; array(1,2), 'access callback' =&gt; true, 'type' =&gt; MENU_CALLBACK, ); </code></pre> <p>In the function, I build up some content like so:</p> <pre><code>function my_module_mypage($x, $y) { $output = "foo AND bar!"; return $output; } </code></pre> <p>In the template (again, NOT in my module folder, but in the THEME subfolder "pages", I have:</p> <pre><code>&lt;?php print $content ?&gt; </code></pre> <p>When I go to <a href="http://mysite/mypath/mypage" rel="nofollow">http://mysite/mypath/mypage</a> I get "foo AND bar!"</p> <p>Now for the question. I want a new variable, defined in my_module_mypage(), called '$moar_content'. I want to output $moar_content in my page-mypath-mypage.tpl.php. I only need to do this for this module and for this template. I do not need it theme-wide, so I don't think using mytheme's 'template.php' is appropriate.</p> <p>I think I need to use some kind of preprocessing, but everything I try fails, and everything I read seems to be missing some kind of magic ingredient.</p> <p>My thinking was:</p> <pre><code>function my_module_preprocess_page_mypath_mypage(&amp;$variables) { $variables['moar_content'] = 'OATMEAL'; } </code></pre> <p>or</p> <pre><code>function my_module_preprocess_my_module_mypage(&amp;$variables) { $variables['moar_content'] = 'OATMEAL'; } </code></pre> <p>or something. I'm pretty sure I'm on the right track, but I'm hitting a brick wall.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload