Lullabot Drupal CCK video series
Please share your thoughts on the video - and please fill out this Form
https://spreadsheets.google.
If you have not received a copy of the video, contact me please.
Magento: How to Create an Extension with its own Layout
1. Create your directory structure
app/
etc/
modules/
- GroupName_All.xml
code/
local/
GroupName/
ExtensionName/ (Or whatever your module name might be)
Block/
controllers/
- IndexController.php
etc/
- config.xml
design/
frontend/
default/
yourtemplate/
layout/
extensionname.xml
template/
extensionname/
form/
index.phtml2. Create your config.xml at app/local/GroupName/ExtensionName/etc/config.xml
| XML | | copy code | | ? |
| 01 | |
| 02 | <config> |
| 03 | <modules> |
| 04 | <groupname_extensionname> |
| 05 | <version>0.0.1</version> |
| 06 | </groupname_extensionname> |
| 07 | </modules> |
| 08 | |
| 09 | <frontend> |
| 10 | <routers> |
| 11 | <extensionname> |
| 12 | <use>standard</use> |
| 13 | <args> |
| 14 | <module>GroupName_ExtensionName</module> |
| 15 | <frontname>extensionname</frontname> |
| 16 | </args> |
| 17 | </extensionname> |
| 18 | </routers> |
| 19 | </frontend> |
| 20 | </config> |
And another one at app/etc/modules/GroupName_All.xml . This one enables our extension.
| XML | | copy code | | ? |
| 01 | |
| 02 | <?xml version="1.0"?> |
| 03 | <config> |
| 04 | <modules> |
| 05 | <GroupName_ExtensionName> |
| 06 | <active>true</active> |
| 07 | <codePool>local</codePool> |
| 08 | </GroupName_ExtensionName> |
| 09 | </modules> |
| 10 | </config> |
| 11 |
3. Create your first controller at app/local/GroupName/ExtensionName/controllers/IndexController.php
| PHP | | copy code | | ? |
| 1 | <?php |
| 2 | class GroupName_ExtensionName_IndexController extends Mage_Core_Controller_Front_Action { |
| 3 | public function indexAction() { |
| 4 | $this->loadLayout(); |
| 5 | $this->renderLayout(); |
| 6 | } |
| 7 | } |
| 8 |
You can access this page in http:/localhost/magento//extensionname/ but the complete url is http://localhost/magento/extensionname/{index}/{index} . by default, magento looks for IndexController and indexAction when they are not specified. Refresh your cache and visit the above URL. You should see the default 3-column layout with nothing in the middle. Our next step is to add our “Hello World” content using only a 1-column layout.
4. Reopen our config.xml and add the following inside the <frontend> tag and right after the <routers> tag
| XML | | copy code | | ? |
| 1 | |
| 2 | <layout> |
| 3 | <updates> |
| 4 | <extensionname module="GroupName_ExtensionName"> |
| 5 | <file>extensionname.xml</file> |
| 6 | </extensionname> |
| 7 | </updates> |
| 8 | </layout> |
| 9 |
The above settings tells Magento to look for extensionname.xml in our layout. Create that file in app/design/frontend/default/yourtemplate/layout/extensionname.xml
| XML | | copy code | | ? |
| 01 | <?xml version="1.0"?> |
| 02 | <layout version="0.1.0"> |
| 03 | <default> |
| 04 | </default> |
| 05 | <extensionname_index_index> |
| 06 | <reference name="root"> |
| 07 | <action method="setTemplate"><template>page/2columns-left.phtml</template></action> |
| 08 | </reference> |
| 09 | <reference name="content"> |
| 10 | <block type="core/template" name="extensionname_form_index" output="toHtml" template="extensionname/form/index.phtml" ></block> |
| 11 | </reference> |
| 12 | </extensionname_index_index> |
| 13 | </layout> |
Let me explain what happend here.
The tag extensionname_index_index is generated using the format:
ExtensionName frontname that you specified in the config.xml + the controller name + the action name.
| XML | | copy code | | ? |
| 1 | <action method="setTemplate"><template>page/2columns-left.phtml</template></action> |
| XML | | copy code | | ? |
| 1 | <block type="core/template" name="extensionname_form_index" output="toHtml" template="extensionname/form/index.phtml" ></block> |
Now we need to create our HTML file. Create a file in app/design/frontend/default/yourtemplate/template/extensionname/form/index.phtml (see the similarity in the template attribute above?) and add the following
| HTML | | copy code | | ? |
| 1 | Hello World! |
Refresh your page and you should see a 1-column layout with a Hello world! Try the other columns and add more contents.
Next time, I’ll post how to add forms and use helpers.
Building a Squidoo like application with Drupal
Topicko.com is a squidoo like application with more features that enable users to connect with each other. This site was created using Drupal 6. Today, I’ll discuss one part of the application — how to build a site that allows users to add contents dynamically using squidoo modules.
Modules needed:
- CCK
- Flexifield
- other optional cck modules to your likings. In this example, we will use text, link and emfield
Our goal is to make a content type that enable writers and editors to dynamically add and reorder sections in their content. Sections in this page refers to the “modules” of squidoo, eg Amazon, Poll, RSS feed, Guest book, Text module and Youtube vids.
Steps:
1. First is to install CCK, flexifield and the optional modules (text, link, emfield). For emfield, you may just select the video media.
2. Flexifield only accepts valid content types and not individual cck modules. In order to utilize flexifield, create separate content types for the text, link and emfield which only contains their respective contents for simplicity. You can add more once you are familiar with the steps.
3. Create your primary content type, in this example we will use “squidoo” as our content type. Add a new flexifield. In the flexifield system settings, select the boxes for the Text, Link and Emfield content types. Set the Number of Values to unlimited.
4. Add a new squidoo content.
The following is a shot taken from the actual topicko’s add topic. It will show you how to add new fields and reorder them.
This weeks theme is “Blocks”
- Those with Questions: You must post at least 1 question you may have about blocks.
- Post your question.
- Search for the answer to that question online or ask a co-worker who may be more knowledgeable.
- Post the answers you get.
- Post how getting the answer to your question helped you.
- Those with Experiences to Share: You must post at least 1 experience you have had building blocks.
- Post the client/manager request.
- Post how you decided on implementing the request into a block.
- Post the staging link to the implementation.
- Post a screenshot of the block and where it is on the site so there is no confusion.
http://www.youtube.com/watch?v=Hs_5IT1-K00
Happy sharing!
Drupal Weekly Knowledge Sharing
This page will provide the launching pad for a series of learning and sharing programs that all of us will be a part of. If you have questions on what is being taught or discussed, you must find the answers online or by reaching out to a co-worker. If your level of knowledge is well above the lesson or presentation, please help with answering others questions.
Finally, we believe that everyone on our team has a valuable lesson that may be shared with the rest. Please submit your ideas or cool info you’d like to share with the rest of the team to Chris chris@promethost.com or Matt matt@promethost.com . Some of the best suggestions will be rewarded! Your tip should also include some basic questions that would stimulate further thoughts on the subject or just test the understanding of the lesson.
img_assist inline image does not appear
img_assist will only display images if the Input Format of the current node is Full HTML. You can select the default Input format to HTML by setting it in the Input Format Configuration page (go to Admin > Site Configuraiton > Input Formats). Selecting the Full HTML option is not enough though. We need to configure this so it can recognize the img_assist tag. In the Input Format configuration page again, click the configure link of the Full HTML option. Under the Filters group, make sure to check the Inline images checkbox. As per the description, it will add images to your posts with Image assist.
And that’s it. The images should appear.
Ternary Operator
<?php
if (cond) {
v = value1
} else {
v = value2
}
?>
This code can be expressed using the ternary operator.
<?php
v = cond ? value1 : value2;
?>
Of course we can use the ternary operator with nested conditions.
<?php
v = cond ? (cond1 ? value11 : value12) : (cond2?:value21:value22);
?>
But that isn’t really an advisable option
Drupal Comment Moderation
- allow the author to enable or disable commenting on their post; and
- dictate if they want the comments to be approved or denied first before getting published in the public
In order to get us rolling, we need 3 modules: Rules, CCK and PHP filter. PHP filter is already included in Drupal 6 (or D6 for short) so you have to download the first 2 modules. There are 3 major steps to fullfill this:
- Add a CCK field
- Create a new rule
- Test
Add a CCK field
This step will just mimic how an admin can enable/disable comments. Follow these steps.- Go to Administer > Content management > Content types (this is located in the navigation block. each underlined text means a link in your drupal site)
- Click “manage fields” of the node type you wish. For this tutorial, we will use Page
- Add a new field with the following attributes (you can change this later if you wish)
Label: Comment moderation
fieldname: comment
Type of data to store: Text
Form element to edit the data: Check boxes/radio buttons - On the next page, copy and paste the following text in the Allowed values
0|Disable
1|Read
2|Read/Write - Optionally you can change other attributes and when your done click save button.
Create a new rule
This one will be a bit long but if you are already used to rules, then it is a piece of cake!- Go to Administer > Rules > Triggered rules
- Add a new rule (check the tab)
- Use the following information
Label: Comment moderation
Event: Content is going to be saved
Click save changes button - You have created a new rule! But we are not done yet. Let’s add some conditions (click the add a condition link at the Rule elements group).
- In the next page, select Field has changed option and submit.
- Then we can start adding more information regarding this condition. The only important fields you should fill up is the Field. Make sure to select our newly created CCK field - field_comment. Do not change anything except for the label if you want and then click the Save button.
- You are then redirected to the Comment moderation edit page. Let’s add a new action (click the add an action link at the Rule elements group).
- In the next page, select Execute custom PHP code (that is why we need the PHP filter so we can write some code) and click Forward button.
- Next, edit the label to your liking and in the PHP Code textarea, copy and paste the following:
// change the comment moderation status
$node->comment = $node->field_comments[0]['value'];
return array(”node” => $node); - Click save and we are done.
Testing
We are now ready to test it. Create a new page or edit the page you created before. Try to disable and enable the values and save. It should be working. If not, let me know the problem in the comment box.You might also notice that in your page view, you will see the Comment option has been displayed. We can hide this in the admin. Let’s go back again to our Content type administration area (Administer > Content management > Content types). Click manage fields and then click Display fields tab. Just change the Teaser and Full node column of your field_comment to <Hidden>. It will hide the field to the page view. Check again.
What’s next?
There is no next! If you ever uninstalled Comment module, just deactivate this rule to save some processing time but it’s not required.Browser Test Tools
InnerHTML in Firefox
After much trials-and-error reconstructing the AJAX imported field and searching the net for a possible solution, I came upon this site (http://www.robertnyman.com/2006/04/20/we-all-love-innerhtml/) where the fix came from one of the readers’ comments.
You need to make the form, where the AJAX imported form fields are located, nested correctly. As for my case, it should follow the correct nesting layout between forms and table. So I changed this previous layout:
<table>
<form>
…. Other elements here ..
</form>
</table>
To this:
<form>
<table>
…. Other elements here ..
</table>
</form>
And that did the trick, I was then able to submit values entered from the AJAX generated fields passed through innerHTML in Firefox.
