Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFINCLUDE within CFIF

Enthusiast ,
Nov 12, 2023 Nov 12, 2023

I have some code that draws in multiple templates using CFINCLUDE

 

I was originally redirecting to multiple pages with CFLOCATION but it worked out better if I could pull in those pages on an as needed basis with CFINCLUDE.

 

The question I have is, if these CFINCLUDES are within CFIF statements and the condition is such that they do not need to be loaded, will the code be loaded into the CFM regardless of whether it is needed or not?

 

I'd like to think that they are only accessed and loaded into CF if needed, especially since I've done the work now and this is an after thought/panic 🙂

 

 

TOPICS
Advanced techniques
273
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 12, 2023 Nov 12, 2023

No need to panic, though the worry is understandable. Fortunately, cfinclude is a runtime tag not a compile time one (as an include might be in languages other than cfml); as such, and like any tag in cfml it will run ONLY if that cfif condition is true.

 

This is also provable with a simple test, with a var set only in the include file, which will be "not defined" after the if, if the condition is not true.

 

Let us know how it goes. 

Translate
Community Expert ,
Nov 12, 2023 Nov 12, 2023

No need to panic, though the worry is understandable. Fortunately, cfinclude is a runtime tag not a compile time one (as an include might be in languages other than cfml); as such, and like any tag in cfml it will run ONLY if that cfif condition is true.

 

This is also provable with a simple test, with a var set only in the include file, which will be "not defined" after the if, if the condition is not true.

 

Let us know how it goes. 


/Charlie (troubleshooter, carehart. org)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 12, 2023 Nov 12, 2023

Thanks for the prompt feedback Charlie. This is good news. I expected or at least hoped that would be the answer, but I did worry, I was wondering if it loaded the template into memory but didn't execute it.

 

In that case my code is all good. I should have really thought about it before I changed to work this way.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2023 Nov 12, 2023
LATEST

Glad to have helped--and that it didn't prove to be a problem without your checking in advance. 🙂 


/Charlie (troubleshooter, carehart. org)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources