Tag Archive for template

Template Query Debug

{% if debug %}
Queries

{{ sql_queries|length }} Quer{{ sql_queries|pluralize:"y,ies" }} {% ifnotequal sql_queries|length 0 %} (Show) {% endifnotequal %}
{% for query in sql_queries %}{% endfor %}
# 	SQL 	Time
{{ forloop.counter }} 	{{ query.sql|escape }} 	{{ query.time }}
{% endif %}

source

New Python App Shell

#!/usr/bin/env python
"""
appname v1.0.1 Copyright(c) 2008; Me, Inc.

Description of the program

usage:  appname [-g config ]
-g			config file (default is /usr/local/etc/mcp.conf)
"""

import os, sys, time, string, traceback

def _banner():
"""
Displays a banner announcing what this program is and what it does.
"""

import string

doc = string.split( __doc__, '
' )
s = doc[1] + '
' + doc[3]
n = 4
while doc[n][:6] != 'usage:':
s = s + '
' + doc[n]
n = n + 1

return s + '
'

def _usage():
"""
Displays the command line arguments for this application.
"""

import string

print _banner()

doc = string.split( __doc__, '
' )
n = 0
while ( doc[n][:6] != 'usage:' ):
n = n + 1

s = doc[n]
n = n + 1
while ( len(doc[n]) ):
s = s + '
' + doc[n]
n = n + 1

return s + '
'

def _processOpts():

# Process command line options
import getopt, sys
try:
# If the option takes a parameter, don't forget to add
# a colon immediately after the parameter.
opts, args = getopt.getopt( sys.argv[1:], "g:", "" )
except:
print _usage()
sys.exit( 1 )

config = 'config.file'

for o, a in opts:

if o == "-g":
config = a
else:
# we don't know this command line option
print _usage()
sys.exit( 1 )

return config

# If this module is being run as the main module
if __name__ == "__main__":

# Get our command line options
config = _processOpts()

source

Page Template Header

<?php
/*
Template Name: Snarfer
*/
?>

source

GCC inline Assembly template

asm(".intel_syntax
"
"
"
"
"
".att_syntax
"
:
:
);

source

XHTML Basic 1.1 Document Template

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<meta http-equiv="Cache-Control" content="max-age=200" />
<title>XHTML Basic 1.1</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="author" href="http://design.leerjohnson.com" />
<link type="text/css" media="screen" href="styles/screen.css" rel="stylesheet" />
</head>
<body id="page-id">
<div id="doc">
<div id="hd" >
<h1 id="site-title">site title</h1>
</div>
<div id="bd">
<p>I am a XHTML Basic 1.1 skeleton</p>
</div>
<div id="ft" >
<p>site footer content</p>
</div>
</div>
</body>
</html>

source

mergeDocumentContentX

/*	Parse all TVs in the [content] of a document. $doc_id is the id of the document	*/
function mergeDocumentContentX($doc_id) {
global $modx;

$my_doc = $modx->getTemplateVarOutput('*',$doc_id);
$template = $my_doc['content'];

$replace= array ();
preg_match_all('~[*(.*?)*]~', $template, $matches);
$variableCount= count($matches[1]);
$basepath= $modx->config["base_path"] . "manager/includes";
for ($i= 0; $i < $variableCount; $i++) {
$key= $matches[1][$i];
$key= substr($key, 0, 1) == '#' ? substr($key, 1) : $key; // remove # for QuickEdit format
$value = $my_doc[$key];
if (is_array($value)) {
include_once $basepath . "/tmplvars.format.inc.php";
include_once $basepath . "/tmplvars.commands.inc.php";
$w= "100%";
$h= "300";
$value= $modx->getTVDisplayFormat($value[0], $value[1], $value[2], $value[3], $value[4]);
}
$replace[$i]= $value;
}
$template= str_replace($matches[0], $replace, $template);
//return $template;

$return_vals = array("my_doc" => $my_doc, "template" => $template);
return $return_vals;
}

source

chunkListParser

<?php

$ar_chunks = split(',',$chunks);
$ar_chunks = array_unique($ar_chunks);

$output = '';

foreach ($ar_chunks as $chunk) {
if ($chunk != '') {
$c = $modx->getChunk($chunk);
if ($c) $output .= $c;
}
}

if ($output != '' && isset($wrapperdiv)) {
$output = '<div id="'.$wrapperdiv.'">'.$output.'</div>';
}

return $output;

?>

source

Allow per-region template overrides.

/**
* Return a set of blocks available for the current user.
* Add a per-region template override option
*/
function ogt_blocks($region) {
$output = '';
if ($list = block_list($region)) {
$function = 'region_'. $region;
if ($theme_function = theme_get_function($function)) {
$blocks = array($list);
//leave the buidling to the dedicated function
$output = call_user_func_array($theme_function, $blocks);
}
else {
foreach ($list as $key => $block) {
//Build the string ourselves.
$output .= theme('block', $block);
}
}
}

// Add any content assigned to this region through drupal_set_content() calls.
$output .= drupal_get_content($region);

return $output;
}

/**
* Template/theme for the region named "siteinfo" (footer)
*
* @return void
**/
function ogt_region_siteinfo($blocks)  {
return _phptemplate_callback('region_siteinfo', array('blocks' => $blocks));
}

//-- in a templatefile region_siteinfo.tpl.php, put something like this:
<?php foreach ($blocks as $block => $block) : ?>
<?php print theme('block', $block); ?>
<?php endforeach; ?>

source

Easy debug variable to find what vars are available in a tpl.php file

/**
*/
function _phptemplate_variables($hook, $vars) {
//...
$vars['args'] = $vars; //TODO: remove this debug variable.
return $vars;
}

source

Flash 9 Class Template (MovieClip)

/** -----------------------------------------------------------
* Class Name
* -----------------------------------------------------------
* Description:
* - ---------------------------------------------------------
* Created by:
* Modified by:
* Date Modified:
* - ---------------------------------------------------------
* Copyright ©2008 Winton DeShong
* - ---------------------------------------------------------
*/
package com.wintondeshong.userinterface
{
import flash.display.MovieClip;

public class DataRow extends MovieClip{

/** -----------------------------------------------------------
* Constructor
* -----------------------------------------------------------
*/
public function DataRow(){
trace ("DataRow Loaded");
};

/** -----------------------------------------------------------
* Properties
* -----------------------------------------------------------
*/

/** -----------------------------------------------------------
* Public Methods
* -----------------------------------------------------------
*/

/** -----------------------------------------------------------
* Private Methods
* -----------------------------------------------------------
*/

}

}

source