In my website I needed to get a list of s9y top-level categories to create links to them form my page to the blog. I used the following code to accomplish it.
// Switch to the Serendipity path. We need to use chdir so that the s9y framework can use its relative calls.
$oldDir = getcwd();
chdir('blog');
// Start the Serendipity API
require 'serendipity_config.inc.php';
// Get the categories
$cats = serendipity_fetchCategories(null, null);
// Switch back to original directory
chdir($oldDir);
I then parsed the array and outputted the info to make links. This all worked great!
In my template file in s9y, however, this doesn't work. How can I call serendipity_fetchCategories from my template file? This is used in a navigation bar across the top with drop down menus for each category. I want the same nav bar to function the same from my website or from s9y. However, I can't figure out how to call this function from my template file.
Thanks,
John
PS: website is http://www.gravleyenterprises.com/
How can I get categories from within a template file
Re: How can I get categories from within a template file
Hi John
Did you ever try to have a look into all set s9y template vars?
Like
Maybe, the variable you are searching for is set already and you don't need the other code?
or u use something like this
{serendipity_showPlugin class="serendipity_categories_plugin" side="*"}
Ian
Did you ever try to have a look into all set s9y template vars?
Like
Code: Select all
// view all smarty template vars
echo '<pre>';
print_r( $serendipity['smarty']->get_template_vars() );
echo '</pre>';
or u use something like this
{serendipity_showPlugin class="serendipity_categories_plugin" side="*"}
Ian
Re: How can I get categories from within a template file
Hey Timbalu,
I did look at that and it works great on the index page, but when one clicks on one of the categories, it doesn't have the list of categories in the data. I use a plugin for the categories for the sidebar, but I need to have control over the display of the info, and serendipity_fetchCategories() gives me the data so I can format it how I need, whereas the plugins just output the data with css as your only formating options.
Thansk.
I did look at that and it works great on the index page, but when one clicks on one of the categories, it doesn't have the list of categories in the data. I use a plugin for the categories for the sidebar, but I need to have control over the display of the info, and serendipity_fetchCategories() gives me the data so I can format it how I need, whereas the plugins just output the data with css as your only formating options.
Thansk.
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: How can I get categories from within a template file
Hi!
The PHP code calls are not all available in s9y smarty templates. Do utilize that, you have two options.
1: You edit/create a template's config.inc.php file, and use $serendipity['smarty']->register_function(...) calls for each s9y API function you want to wrap, and add a wrapper function call that uses the smarty function PHP syntax. This is the "cleaner" way, but also much more work to code.
2: You edit/create your template's config.inc.php and set $serendipity['smarty']->security = false;. This allows you to use Smarty's {php}...{/php} calls, where you can simply code your PHP parts into. This is a bit dirty, but has the quickest access.
HTH,
Garvin
The PHP code calls are not all available in s9y smarty templates. Do utilize that, you have two options.
1: You edit/create a template's config.inc.php file, and use $serendipity['smarty']->register_function(...) calls for each s9y API function you want to wrap, and add a wrapper function call that uses the smarty function PHP syntax. This is the "cleaner" way, but also much more work to code.
2: You edit/create your template's config.inc.php and set $serendipity['smarty']->security = false;. This allows you to use Smarty's {php}...{/php} calls, where you can simply code your PHP parts into. This is a bit dirty, but has the quickest access.
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: How can I get categories from within a template file
Hi Garvingarvinhicking wrote:1: You edit/create a template's config.inc.php file, and use $serendipity['smarty']->register_function(...) calls for each s9y API function you want to wrap, and add a wrapper function call that uses the smarty function PHP syntax. This is the "cleaner" way, but also much more work to code.
Is it possible to register NON-API functions in config.inc.php to smarty with this too? Like
Code: Select all
function foo() { //something }
$serendipity['smarty']->register_function('isfoo', 'foo');
Ian
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: How can I get categories from within a template file
Hi!
This is possible as long as your function has the (&$smarty, $params) function header; if not you need to have a wrapper function, like the s9y api does for usual code calls. Since this is much overhead, it's not done for every PHP function.
Regards,
Garvin
This is possible as long as your function has the (&$smarty, $params) function header; if not you need to have a wrapper function, like the s9y api does for usual code calls. Since this is much overhead, it's not done for every PHP function.
docs/NEWS says since 1.1-alpha5.And second question, since which S9y version is it possible to use a template/config.inc.php file?
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: How can I get categories from within a template file
molto bene!
Danke
Ian
Code: Select all
function foo($params, &$smarty) { $b = 'something'; return $b; }
$serendipity['smarty']->register_function('isfoo', 'foo');
{isfoo} no $
Ian