Skip to content

Instantly share code, notes, and snippets.

@jessegreathouse
Created April 6, 2011 19:25
Show Gist options
  • Save jessegreathouse/906343 to your computer and use it in GitHub Desktop.
Save jessegreathouse/906343 to your computer and use it in GitHub Desktop.
how to use custom headers and footers with CDclient [theoretically]
<?php
/*
We've built in the ability to only select certain content by using CSS selectors. This may yield unexpected results if not used carefully and is subject to change. for example, you may wish to only select the body head and form, and you may wish to store those things in variables so you can mix in your own content. Here is how you'd do something like that:
*/
include('library.php');
$client = new cdClient();
$client->request();
$client->initHeaders();
/*
It is currently important to make the distinction between types of content. Your index.php file is responsible for handling the JavaScript and CSS resources as well as the HTML and you wouldn't want this to be done for those resources, so in order to make that distinction you should create a condition for handling if this is not html:
*/
if (!$client->isType('html')) {
echo $client->getContent();
exit();
}
/*
What this does is a string match on the "Content Type" header of the page that the client is handling. If this is the kind of page we want to manipulate then the content type header will look similar to this: Content Type: Text/html. If that string "html" is not found it will infer that it is some other content type and just echo out the content as usual and then exit the script.
If this is found to be an html type page, then you will have a chance to do some post engineering:
*/
$cdCss = $client->getContent('link');
$cdJs = $client->getContent('script');
$cdBase = $client->getContent('base');
$cdForm = $client->getContent('form');
/* now feel free to use these elements in your template or page like this: */
?>
<html>
<head>
<?php echo $cdBase; ?>
<title>My Custom Form</title>
<?php echo $cdCss; ?>
<?php echo $cdJs; ?>
</head>
<body>
<p> Hi Everybody! please fill out my form</p>
<?php echo $cdForm; ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment