Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Navigation

How to get $file_path when "SEF" and "Normalize Friendly URLs" are enabled

Last updated on 3 years ago
S
sasha2002Junior Member
Posted 3 years ago
Hi,
When "Search Engine Friendly URL (SEF)" AND "Normalize Friendly URLs" are enabled have this for Homepage :

Path to File:
Request URI: index.php
1. index.php : No matching Alias found.
2. index.php : No matching Alias Pattern found.
3. File path is empty.

How is possible to get "$file_path" ?
Want to do something like that :
$is_home = 'index.php' == $file_path;
O other pages i got :
Path to File: infusions/articles/articles.php
Request URI: articles
and $file_path="/articles"

And second question is: How i can get title of the Page for "function render_page() {"
$title here does not have power
R
Anonymous UserVeteran Member
Posted 3 years ago

Quote

How is possible to get "$file_path" ?

$file_path = str_replace(ltrim(fusion_get_settings('site_path'), '/'), '', preg_replace('/^//', '', FUSION_REQUEST));
if (fusion_get_settings('site_seo') && defined('IN_PERMALINK')) {
 $file_path = \PHPFusion\Rewrite\Router::getRouterInstance()->getCurrentURL();
}

if ($settings['opening_page'] == $file_path) {
 // content visible only on homepage
}


Quote

How i can get title of the Page for "function render_page() {"

Use this function https://php-fusion.co.uk/docs/phpfusi...t_settings
Print $settings variable to see available settings, page title should be on top.
S
sasha2002Junior Member
Posted 3 years ago
I've got "" on $file_path.
And no page title in $settings. This is var_dump

array(133) {
 ["sitename"]=>
 string(31) "REDACTED"
 ["siteurl"]=>
 string(23) "https://site.com/"
 ["site_protocol"]=>
 string(5) "https"
}
Edited by Anonymous User on 26-10-2021 12:58, 3 years ago
R
Anonymous UserVeteran Member
Posted 3 years ago

Quote

I've got "" on $file_path.

Here is another solution
if (fusion_get_settings('site_seo')) {
   $params = http_build_query(\PHPFusion\Rewrite\Router::getRouterInstance()->getFileParams());
   $path = \PHPFusion\Rewrite\Router::getRouterInstance()->getFilePath();
   $file_path = '/'.(!empty($path) ? $path : PERMALINK_CURRENT_PATH).($params ? "?" : '').$params;
} else {
   $file_path = '/'.PERMALINK_CURRENT_PATH;
}

if (fusion_get_settings('opening_page') == 'index.php' && $file_path == '/' || $file_path == '/'.fusion_get_settings('opening_page')) {
   // content visible only on homepage
}

I'll add function for this to core, there are many situations when you need to display something only on homepage.

Quote

And no page title in $settings.

render_page() function displays current page layout and not custom pages. Specify what you want..

'sitename' is page title or if you want entire current title, there is function https://php-fusion.co.uk/docs/phpfusi.../get_title


Btw. here is template for Custom pages, you can copy this code into your theme and modify it https://github.com/PHPFusion/PHPFusio...ge.tpl.php
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
You cannot set up a bounty in this discussion thread.
Moderator: Support Team
Users who participated in discussion: sasha2002, RobiNN