Download & Extend

Access Page Variables/Theme Settings from within Panels

Project:Panels
Version:7.x-3.3
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Panels has a section called "Page Elements" where you can access the Site Logo that is set in theme settings.
I have created my own theme setting called Telephone where users can enter a telephone number.
I would like to make this available to Panels. How can I do this?

In my template.php file, I used the following code:

function legendary_preprocess_page(&$variables) {
$telephone = theme_get_setting('telephone');
$variables['telephone'] = $telephone;
}

This makes the telephone variable available in the page, but I'm not show how to select it in Panels.

Comments

#1

Status:active» fixed

You would need to write a content type plugin that makes this available. You can see the existing ones in ctools/plugins/content_types/page -- they are some of the simplest content type plugins there are.

You could mostly cut & paste a plugin and change it appropriately, though you do need to be sure you do the basics to implement content type plugins, which means implementing hook_ctools_plugin_directory to tell the system where to look for your plugin.

#2

Status:fixed» active

The Ctools advanced help has some really good documentation on how to do this. It says:

themes add a line to their info file:
plugins[module][type] = directory

Does this mean I can implement a content type plugin in the theme without having to create a separate module?
If so, the code I am using in my info file is this: plugins[panels][content_types] = plugins/content_types/pages Is that correct?

Also, in ctools/plugins/content_types/page/page_slogan.inc it has this line:
$block->content = (theme_get_setting('toggle_slogan') ? filter_xss_admin(variable_get('site_slogan', '')) : '');

My theme setting is called '['footer']['footer_about']', so will the following work in custom content type plugin?:
  $block->content = (theme_get_setting('footer_about') ? filter_xss_admin(variable_get('footer_about', '')) : '');
I've tried it, but it doesn't seem to work.

Thanks for any help that can be offered!

#3

Status:active» fixed

Unfortunately content types are not set up to allow themes to create them, so you'll need to use a module.

I believe that line of code will work, but I am not too experienced with theme_get_setting(), so you may have to explore that one more deeply on your own.

#4

Nick Lewis has an excellent tutorial on how to create a content type as module, for anyone else who has the same problem. He has even posted a template to download.
In the example I have posted above, the code to get the theme setting would be:

$block->content = (theme_get_setting('footer_about') ? theme_get_setting('footer_about') ) : '');

Hope that helps someone!

#5

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.