Category Archives: How To

Alfred.app Apple / Mac How To

Running iOS Simulator with Alfred.app

Today I realized that I could start the iOS Simulator (that ships with Xcode) via Alfred! I did this by navigating to the path below in Finder, then dragging-and-dropping the folder into Alfred’s “Search Scope”:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/
Developer/Applications/

Note: You will likely need to right-click Xcode.app and “Show contents” to browse the directories within. 

Alfred’s “Search Scope” settings can be found under Preferences -> Features -> Default Results.

Expression Engine How To

Git is magnificent.

Git is magnificent. No single tool has saved me as much time, effort, and sanity as Git and I recommend it’s use to every developer, designer, and power-user I know.

What’s so great about Git?

I had planned to sit down this evening and write an article extolling the virtues of git and version control, but I’ve discovered loads of articles who have done it much better than I ever could. So instead of reinventing the wheel, I will merely redirect you to to these articles for an introduction to git, then make a few additional points.

Required reading:
Designers read Git: A Designer’s Perspective.
Developers read the article above and Git for the nervous developer.

Extracurricular:
A SlideShare presentation on the more technical aspects of Git.

Git options on Mac OS X: 

  • GitTower – Commercial gui client ($69)
  • git-osx-installer – open-source installation of command-line git
  • port install git-core – using mac ports (formerly darwin) package manager

Git options for Windows users:

  • TortiseGit - open-source client with Windows Explorer integration
  • MSysGit - open-source command-line client
  • SmartGit - commercial ($69)

Git repository hosting:

  • Github – Packages geared toward many users and better collaboration, less repositories
  • Beanstalk – Repository hosting with packages geared toward fewer developers, but more repositories per account tier.
  • Unfuddle – Git and SVN hosting, geared toward project managements (has wikis, gantt charts, etc). Silly name.

More resources:

Pro Git – A free git bible.

Expression Engine How To

Adding a “Prepend” Option to URLs generated by the {exp:structure:nav} Tag

In mod.structure.php function nav() insert the highlighted line:

[php highlight="81" firstline="76"]

// Miscellaneous parameters
$depth = $this->EE->TMPL->fetch_param(‘limit_depth’, 1);
$exclude = $this->EE->TMPL->fetch_param(‘exclude’, NULL);
$mode = $this->EE->TMPL->fetch_param(‘mode’, ‘sub’);
$prepend = $this->EE->TMPL->fetch_param(‘prepend’, NULL);

[/php]

And before the end of the function, replace the line setting $html with the following highlighted line:

[php highlight="124" firstline="120"]

if ($entry_id === FALSE)
$entry_id = 0;

$html = $this->sql->generate_nav($entry_id, $current_id, $depth, $exclude, $mode, $prepend);

return $html;
}

[/php]

Now open sql.structure.php.

Locate the generate_nav() function (around line 479) and change the function definition to the first highlighted line below. Also update the function call to get_selective_data() (around line 489) to pass through that $prepend value as shown in the second line below.

[php highlight="479,489" linestart="474"]

/**
* Get the HTML code for an unordered list of the tree
* @return string HTML code for an unordered list of the whole tree
*/
function generate_nav($entry_id, $current_id = FALSE, $depth = 1, $exclude = NULL, $mode, $prepend=null)
{

$html = ”;
$separator = $this->EE->config->item(‘word_separator’) != "dash" ? ‘_’ : ‘-’;

// Fallback to entry_id if no current_id (e.g. sitemap usage)
if ($current_id === FALSE)
$current_id = $entry_id;

$pages = $this->get_selective_data($entry_id, $depth, $exclude, $current_id, $mode, $prepend);
$pages = $this->add_attributes($pages, $current_id, $mode);

[/php]

Now we update get_selective_data() (around line 139) to make use of the passed data:

[php linestart="130" highlight="139"]
/**
* Get selective data on all Structure Channels
* The Godfather of all Structure queries
*
* "I’m gonna make you a query you can’t refuse."
*
* @return array
*/
function get_selective_data($parent_id = NULL, $depth = 1, $exclude = NULL, $current_id = NULL, $mode = NULL, $prepend = NULL)
{
$pages = $this->get_site_pages();

[/php]

Please take a moment and go back to thoroughly review the inline comment.

Finally, in the same get_selective_data() function find the code which sets “$data[$row['entry_id']]['uri']” (around line 286) and replace it with the highlighted code:

[php linestart="281" highlight="287"]

// build out the main data array
foreach ($page_data as $row)
{
$data[$row['entry_id']] = $row;
//$data[$row['entry_id']]['uri'] = $this->EE->functions->create_page_url($pages['url'] .’/’. $prepend, $pages['uris'][$row['entry_id']]);
$data[$row['entry_id']]['uri'] = $this->EE->functions->create_page_url($pages['url'] .’/’. $prepend, $pages['uris'][$row['entry_id']]);
$data[$row['entry_id']]['slug'] = $pages['uris'][$row['entry_id']];
$data[$row['entry_id']]['classes'] = array();
$data[$row['entry_id']]['ids'] = array();

[/php]

That does it. You should now be able to add an arbitrary string to the beginning of the path portion of a URL.

Example code:

[php htmlscript="true" wraplines="true"]

{exp:structure:nav mode="sub" lang="{site_lang}" start_from="/{segment_1}" }

[/php]

Note: {site_lang} is a snippet I’ve created in the EE back end that always echos the current site “stub”. Also, the “start_from” attribute isn’t required.

You can use the same principles in this post to prepend strings to the Structure breadcrumbs and other parts of Structure. Please be aware, however, if you modify the core code the Structure guys are not going to be able to help you with any problems you might encounter.