RocketModule - theming http://rocket.local/categories/theming en Three little lines of code that you may learn to love http://rocket.local/blog/three-little-lines-code-you-may-learn-love <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Assignment: Create a highly customized page/node in Drupal and: </p><ul><li>Be able to develop the page/node using our text editor of choice and avoid the time-consuming and not-intended-to-be-developer friendly Drupal node-editing interface</li> <li>Optionally be able to decide whether to have the page/node be editable by the via the Drupal UI or not.</li> </ul><p>Sure, we could do this by creating a page-node-xx.tpl.php template file (where 'xx' is the node id number), but that's just a major hassle later on when updating/theming things and it won't give us the flexibility of being able to let an end-user edit things.</p> <p>In this case, the thing to do is to create a file called my-file.php (.php because we want our text-editor to still recognize it correctly), put it in our theme folder, check the PHP input filter on the node itself, and then place this code in a node:</p> <div class="codeblock"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Include a file with the rendering of a node so that you can edit in text editor and just refresh without having to use Drupal UI<br /></span><span style="color: #0000BB">$filename </span><span style="color: #007700">= </span><span style="color: #DD0000">'my-file.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$path_to_file </span><span style="color: #007700">= </span><span style="color: #0000BB">drupal_get_path</span><span style="color: #007700">(</span><span style="color: #DD0000">'theme'</span><span style="color: #007700">, </span><span style="color: #DD0000">'your_themes_name'</span><span style="color: #007700">) .</span><span style="color: #DD0000">'/'</span><span style="color: #007700">. </span><span style="color: #0000BB">$filename</span><span style="color: #007700">;<br />include(</span><span style="color: #0000BB">$path_to_file</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div> <p>What this will do is look for the file you placed inside your theme folder called "my-file.php" and render it. Which means that you make changes directly to my-file.php without having to touch the node itself and thus simply refresh your node anytime you make changes to the file.</p> <p>This method has the advantage of: </p><ul><li>Saving a ton of time and headaches of dealing with the Drupal interface and doing without your favorite code editing tool.</li> <li>After you're finished you'll have the option of choosing to replace the include-code with the final code inside your file so that an end-user can edit it within UI... </li><li>...or you can just keep things like this and be able to do cool things like check the code into version control, which means that you basically get many of the benefits of a tpl.php file without the cost of one.</li> </ul><p>Enjoy and happy coding. :-)</p> <p><strong>UPDATE</strong>: if this all sounds like a good idea to you, head over to the <a href="http://drupal.org/project/savetofile">project page for Save-to-File</a> which was inspired by a conversation in the comment thread below.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Categories:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/categories/drupal" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Drupal</a></div><div class="field-item odd"><a href="/categories/php" typeof="skos:Concept" property="rdfs:label skos:prefLabel">php</a></div><div class="field-item even"><a href="/categories/development" typeof="skos:Concept" property="rdfs:label skos:prefLabel">development</a></div><div class="field-item odd"><a href="/categories/theming" typeof="skos:Concept" property="rdfs:label skos:prefLabel">theming</a></div></div></div> Sat, 22 Mar 2008 04:41:55 +0000 Caleb Gilbert 74 at http://rocket.local http://rocket.local/blog/three-little-lines-code-you-may-learn-love#comments Advanced Theme Construction Kit (ATCK) updated for Drupal 6 http://rocket.local/blog/advanced-theme-construction-kit-atck-updated-drupal-6 <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>The <a href="http://drupal.org/project/atck">Advanced Theme Construction Kit</a>, which integrates a derivative of the Yahoo grids CSS library within a Drupal framework, was updated and released for Drupal 6 today. </p> <p><strong>Something new</strong><br /> After religiously following the changes to Drupal 6's theme-layer for many months now, as well as actively coding a Drupal 6 module for the past month and a half, I was thinking that upgrading ATCK was going to be a snap...</p> <p>In some ways it was, but the Drupal 5 to Drupal 6 theme conversion was by far the most complicated theme update I've seen since being involved with Drupal (4.5 onward). As it turns out the Drupal 5 template.php file for ATCK was almost completely useless, and it was with great thanks that I (again) borrowed heavily from <a href="http://drupal.org/project/hunchbaque">Hunchbaque's</a> template.php in order to get the desired granularity for classes/id's.</p> <p>One area I did depart from core and the Hunchbaque theme on is the handling of css files. Allowing for the possibility that there is something that I'm 'missing', I can't say that I'm currently very happy with Drupal's new method of adding stylesheets via .info files, nor with the functions that Hunchbaque currently uses in it's template.php to add IE-only css. The core method of stylesheet handling makes stylesheets a bit of a pain to refresh, and I found both methods to be unreliable with respect to conditionally adding stylesheets.</p> <p>In the end 'old fashioned' conditional statements were implemented within page.tpl.php, and a custom function added to template.php. Along with being reliable, this combo provides the ability to tell Drupal to NOT import specific core css files (e.g., if you don't want the node.css file loaded - simply add a line to the function inside ATCK's template.php and node.css never gets loaded).</p> <p><strong>Something old</strong><br /> The most satisfying part of the upgrade was that the centerpiece of ATCK, the Yahoo Grids-inspired CSS library, did not require a single change. So this part has proven to indeed be modular and Drupal version independent. :-)</p> <p><strong>Future development plans for ATCK</strong><br /> * Possibly add the edit functionality that the Zen theme has introduced to make managing blocks and views easier.</p> <p>~~~</p> <p><a href="http://groups.drupal.org/node/9718">HigherVisibility is looking for assistance!</a></p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Categories:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/categories/drupal" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Drupal</a></div><div class="field-item odd"><a href="/categories/development" typeof="skos:Concept" property="rdfs:label skos:prefLabel">development</a></div><div class="field-item even"><a href="/categories/atck" typeof="skos:Concept" property="rdfs:label skos:prefLabel">atck</a></div><div class="field-item odd"><a href="/categories/theming" typeof="skos:Concept" property="rdfs:label skos:prefLabel">theming</a></div></div></div> Sat, 15 Mar 2008 23:01:30 +0000 Caleb Gilbert 72 at http://rocket.local http://rocket.local/blog/advanced-theme-construction-kit-atck-updated-drupal-6#comments