-1

How we add more fields in the appearance -> settings -> "my template"

So that the background image shows several titles and other information.

enter image description here

I added the fields in theme-settings.php, but when i am added new they cannot display at frontend. I changed the print code as well in template.php(code below).

for ($i = 0; $i < count($banners); $i++) {
        $output .= '{ 
            "image" : "' . file_create_url($banners[$i]['image_path']) . '",
            "title" : "' . "<h2>" . fancy_title(t('@image_title', array('@image_title' => t($banners[$i]['image_title'])))) . "</h2>" . '",
            "subtitle" : "' . "<h3>" . fancy_title(t('@image_subtitle', array('@image_subtitle' => t($banners[$i]['image_subtitle'])))) . "</h3>" . '",
        },';
    }   

I tested and if i change 'subtitle' to 'title' i can print that, but not both.

If anyone can give me a hint i would appreciate. Cheers

EDIT

The fields that i need to print, are created in theme-settings.php with this code,

 // Image title
$img_form['image_title']       = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $image_data['image_title']
);
// Image SUB title
$img_form['image_subtitle']       = array(
    '#type' => 'textfield',
    '#subtitle' => t('subTitle'),
    '#default_value' => $image_data['image_subtitle']
);

printed in template.php with this code,

 for ($i = 0; $i < count($banners); $i++) {
        $output .= '{ 
            "image" : "' . file_create_url($banners[$i]['image_path']) . '",
            "title" : "' . "<h2>" . fancy_title(t('@image_title', array('@image_title' => t($banners[$i]['image_title'])))) . "</h2>" . '",
            "subtitle" : "' . "<h3>" . fancy_title(t('@image_subtitle', array('@image_subtitle' => t($banners[$i]['image_subtitle'])))) . "</h3>" . '",
        },';
    }

and called in page.tpl.php with this code,

 <?php if (theme_get_setting("slideshowType")=="image") : ?>

So, the second field created shows in drupal- settings - template, stores the info in the database, but isn't printed correctly in page.tpl

If any more info is needed i will provide it.

Ps. I'm new to drupal and PHP.

2 Answers 2

0

If you want to add more items/theme in your home page template, do the following the steps..

  1. Create a new tpl by editing existing page.tpl.php.
  2. Add your fields into new tpl.
  3. Name your new tpl as page--front.tpl.php.
  4. Put your new template in current-theme/templates.

If you want to add more items in your theme options page do it in

hook_form_system_theme_settings_alter()

3
  • I realized that i explained the problem poorly, i added more info. Thanks for your time!
    – Nuno cruz
    Oct 15, 2015 at 9:36
  • in page.tpl you can access image_title value by calling theme_get_setting("image_title"); and theme_get_setting("image_subtitle"); for image_subtitle value
    – Abin
    Oct 15, 2015 at 9:46
  • I try'd to use your solution, but with no success, but it gave-me some ideas to try.
    – Nuno cruz
    Oct 15, 2015 at 13:25
0

After reading the answer given, i searched in the code to find how to pass the 2 fields, and after sometime i realized that was the Javascript that was in charge to print the variables in the target ID, and not the PHP

The original that printed the field:

 if (a(vars.slide_caption).length) {
            (api.getField("**title**")) ? a(vars.slide_caption).html(api.getField("**title**")) : a(vars.slide_caption).html("");
        }

To print 2 fields:

 if (a(vars.slide_caption).length) {
            (api.getField("**title**") && api.getField("**subtitle**")) ? a(vars.slide_caption).html(api.getField("**title**") + api.getField("**subtitle**")) : a(vars.slide_caption).html("");
        }

Thank you for your time. Would give +vote, but i don't have permissions. Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.