vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Format question: why is fetch_template surrounded with single quote+period? (https://vborg.vbsupport.ru/showthread.php?t=180552)

raztrip 05-26-2008 11:06 AM

Format question: why is fetch_template surrounded with single quote+period?
 
Hello,

Can anyone explain why the format for fetching templates includes the template name enclosed in single quotes and periods?

eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('WHOSONLINE') . '");');

Thank you,

R

Dismounted 05-26-2008 11:12 AM

String Concatenation :)

nexialys 05-26-2008 11:25 AM

you could also make it this way:
eval(print_output(fetch_template('WHOSONLINE')));

but only if your server is PHP 5.1 and newer... it would not be compatible with older versions, so it would break a lot of vBulletin right now... in the future, this structure will change...

raztrip 05-26-2008 11:25 AM

I thought it might be it, but I still can't see how it works in this case.

Why are there single quotes inside the double quotes?

Which string does this concatenate to?
Why not use the .= format?

Quote:

Originally Posted by Dismounted (Post 1531781)
String Concatenation :)


Opserty 05-26-2008 12:51 PM

Work from the inside out...
  1. [minicode]fetch_template()[/minicode] - fetches the template's HTML data (as a string) and returns it.
  2. The concatanation appends the template data to the string, the [minicode]$navbar =...[/minicode]
  3. Finally the [minicode]eval()[/minicode] evaluates the string as PHP code, so [minicode]$navbar[/minicode] becomes a proper variable instead of just a string. It will also mean that variables in the templates will assume their values assigned to them earlier in the script.

The start of this page shows the differences between single & double quotes and may help to explain why there are double quotes inside single quotes.

Its not hard to understand but if you are not well versed in PHP could take a while to explain it fully.

Dismounted 05-27-2008 06:36 AM

Quote:

Originally Posted by raztrip (Post 1531788)
Why not use the .= format?

Because you can't. There isn't a "=" anywhere, so you can't use a ".=".

raztrip 05-27-2008 09:41 AM

First, thank you all for replying. I've read the guide on single and double quotes, and understood it, including the concatenation examples.

Now, if we take just this part:
$navbar = "' . fetch_template('navbar') . '";

I fail to understand why it isn't written as:
$navbar .= "fetch_template('navbar')";

Also, seeing as how PHP would recognize a function inside quotes as a string (I'm talking about 'fetch_template...'), does eval overcome this by treating everything to the right of it as possible PHP code?

Thank you,

R

Quote:

Originally Posted by Dismounted (Post 1532640)
Because you can't. There isn't a "=" anywhere, so you can't use a ".=".


Dismounted 05-27-2008 09:47 AM

That's different. eval() does indeed parse everything as PHP code. fetch_template() parses templates from the conditionals to proper PHP code which can be understood. We are concatenating fetch_template()'s output to $navbar, what you suggest is concatenating fetch_template()'s output to the end of navbar, and what will be concatenated will be the PHP code that fetch_template() outputs, and that will not be parsed by eval().


All times are GMT. The time now is 01:46 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01787 seconds
  • Memory Usage 1,724KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete