Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3944502
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:54:29+00:00 2026-05-20T00:54:29+00:00

Although I don’t think the question was as good as it could be, let

  • 0

Although I don’t think the question was as good as it could be, let me try to explain better here.

I have a site using SMARTY 3 as the template system. I have a template structure similar to the below one:

/templates/place1/inner_a.tpl
/templates/place1/inner_b.tpl

/templates/place2/inner_b.tpl
/templates/place2/inner_c.tpl

/templates/default/inner_a.tpl
/templates/default/inner_b.tpl
/templates/default/inner_c.tpl

These are getting included on the parent template using

{include file="{$temp_folder}/{$inner_template}"}

So far great. What I wanted to do is having a default for, in the case that the file {$temp_folder}/{$inner_template} does not exists, it uses the equivalent file at default/{$inner_template}.

i.e. If I do {include file="place1/inner_c.tpl"}, since that file does not exists it in fact includes “default/inner_c.tpl”

Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:54:29+00:00Added an answer on May 20, 2026 at 12:54 am

    You’ll have to do it in php, smarty doesn’t have a way to check if a file exists.

    You could write your own template handler too.

    <?php
    // put this function somewhere in your application
    
    function make_template ($resource_type, $resource_name, &$template_source, &$template_timestamp,
    &$smarty_obj)
    {
        if( $resource_type == 'file' ) {
            if ( ! is_readable ( $resource_name )) {
                // create the template file, return contents.
                $template_source = "This is a new template.";
                require_once SMARTY_CORE_DIR . 'core.write_file.php';
                smarty_core_write_file( array( 'filename'=>$smarty_obj->template_dir . DIRECTORY_SEPARATOR . $resource_name, 'contents'=>$template_source ), $smarty_obj ); 
                return true;
            }
        } else {
            // not a file
            return false;
        }
    }
    
    // set the default handler
    $smarty->default_template_handler_func = 'make_template';
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although somewhat related to this question , I have what I think is a
I don't have a specific question here but I'm more looking for some guidance
Although I don't have an iPhone to test this out, my colleague told me
I know I need to have (although I don't know why) a GROUP BY
I recently switched from Eclipse to NetBeans (although I don't have any current Eclipse
Foreword: Although I don't think it's exactly a duplicate, feel free to close if
I don't see a Visual Studio plugin for it (although I didn't look that
Although my question might seem abstract I hope it's not. Suppose I develop an
Although ASP.NET MVC seems to have all the hype these days, WebForms are still
Although I grasp the concept of Bitwise Operators, I can't say that I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.