Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Basic Codeigniter model template

// Basic Codeigniter model template.

<?php

class Model_name extends Model {

    function Model_name()
    {
        /* Call the Model constructor */

        parent::Model();
    }

	function name_of_function()
    {      

    }

}

?>

Linking to articles using the article’s weblog in ExpressionEngine

I have an index template that displays articles from several sections (weblogs), but when linking to an article we must specify the template_group and template to use. I have different template groups for each section, and want to use them as they define the article’s URL. However, the obvious way of using {title_permalink="{weblog_short_name}/index"} doesn’t work (although we can use {segment_#} like this).

You can do this by passing the {weblog_short_name} and {entry_id} of each article to an embedded template using embedded variables:

<!-- the index template that calls the embedded template -->
{exp:weblog:entries weblog="not pages" orderby="date" sort="desc" limit="10" disable="categories|comments|member_data|pagination|trackbacks"}
<div class="article">
{date_heading}<h3 class="date">{entry_date}</h3>{/date_heading}
<h3>{weblog}</h3>
<h2 class="title"><a href="{target_url}" title="{target_title}">{title}</a></h2>
{summary}
<!-- the next line embeds the template and sets the variables -->
<p><a href="{embed="snippet/body-hp-link" the_weblog="{weblog_short_name}" the_entry_id="{entry_id}"}">Read more</a> or comment&hellip;</p>
</div>{/exp:weblog:entries}


<!-- the embedded template -->
{exp:weblog:entries weblog="{embed:the_weblog}" entry_id="{embed:the_entry_id}" dynamic="off" disable="categories|comments|member_data|pagination|trackbacks"}{title_permalink="{embed:the_weblog}/index"}{/exp:weblog:entries}

MailMan listserve signup template

Simple template for adding a MailMan mailing list subscribe form to a page. Found on a mailing list somewhere a long time ago and cleaned up dramatically.

Note: I almost always just include the email and digest options, but I've included the whole spiel for completeness.


<h2>Join the XYZ list</h2>

<form method="post" action="SERVER/mailman/subscribe/LISTNAME">

  <p>
    Your E-mail address: <input type="text" name="email" size="30" value=""><br />
    Your Name (optional): <input type="text" name="fullname" size="30" value=""><br />
  </p>

  <p>You may enter a privacy password below. This provides only mild security, but should<br />
  prevent others from messing with your subscription. <b>Do not use a valuable password</b> as it<br />
  will occasionally be emailed back to you in cleartext.</p>

  <p>If you choose not to enter a password, one will be automatically generated for you, and it will<br />
  be sent to you once you've confirmed your subscription. You can always request a mail-back<br />
  of your password when you edit your personal options.</p>

  <p>
    Password choice: <input type="password" name="pw" size="15"><br />
    Confirm Password: <input type="password" name="pw-conf" size="15">
  </p>

  <p>
    Would you like to receive list mail batched in a daily digest? (You may choose NoMail after you join.)<br />
    <input type="radio" name="digest" value="0" checked> No 
    <input type="radio" name="digest" value="1"> Yes <br />
  </p>
  
  <p><input type="submit" name="email-button" value="Subscribe"></p>

</form>


default layout for a controller

// description of your code here
In your controller add the name of the .rhtml file in <project>/apps/layouts/ that you want to use, without the suffix (.rhtml).
When rails spits out your view, it will use this given layout as the container for your rendered action.
layout "<layout_name>"

XHTML 1.0 Strict template

// So I can stop typing it. Includes the basic DIVs I aways seem to use.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="imagetoolbar" content="no" /><!-- kills IE's img toolbar -->
<meta name="MSSmartTagsPreventParsing" content="true" /><!-- kills related links in XP -->
<link rel="stylesheet" type="text/css" href="/styles/main.css" type="text/css" media="screen, projection" />
<!--[if lt IE 7]>
<link rel="stylesheet" href="-/css/screen/patches/win-ie-old.css" type="text/css" media="screen, projection" />
<![endif]-->
<!--[if gte IE 7]>
<link rel="stylesheet" href="-/css/screen/patches/win-ie7-up.css" type="text/css" media="screen, projection" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="/styles/print.css" type="text/css" media="print" />


</head><body><div id="page">



<div id="header">
<h1>Header</h1>
</div><!--END #header-->



<div id="content">
</div><!--END #content -->



<div id="footer">
<h1>Footer</h1>
</div><!--END #footer -->



</div><!--END #page --></body></html>