Imagine the following scenario:
I have a tag that fetches data and provides it as smarty-object or returns false if it is unable to solve a given problem. That works great.
The tag (plug-in) is called with a parameter param which can have a limited number of some string values (~1,000).
I use $smarty.get.param in the plug-in call (simplified)
Code: Select all
{plug_in param=$smarty.get.param}
and map it to the following scheme (simplified)
Code: Select all
RewriteCond %{REQUEST_URI} ^/page-with-plugin
RewriteRule ^([^/]*)/(.+) index.php?page=$1param=$2 [QSA,L]
{plug_in param=$smarty.get.param}
{if $plug_in_result == false}
... this entry does not exist
{else}
... do some stuff with the data
{/if}
This setup works so far. However, the page will always return a status code 200, since the page itself exists and is working correctly. But now, I'd like to send the 404 Error page in case, the plug-in returns a false.
I could successfully return a 404 header with a one-liner UDT. So now I can display some error message and send a 404 header but still it doesn't feel "smooth".
Code: Select all
header("HTTP/1.1 404 Not Found");
Code: Select all
<__html>
...
</__body ... >
{plug_in param=$smarty.get.param}
{if $plug_in_result == false}
{tag_send_404_header}
<h1>404 Error</h1>
{else}
<h1>{$plug_in_result->data_1}</h1>
{/if}
...
{if $plug_in_result == false}
<div>{global_content name='error_404_message'}</div>
{else}
<div>{$plug_in_result->data_2}</div>
{/if}
<__body>
</__html>
Ideally, would like to make CMSMS stop rendering the page and return the defined 404 error instead.
I could theoretically conduct a redirect, but this also doesn't sound right as a false result.
It's not that I couldn't live without triggering the CMSMS 404. But I'm still curious whether I can call the 404 via a specific given way.
At the moment I can think of a UDT than fetches the 404 Error data. But that wouldn't be much different.
What could be another approach for a coherent 404 behavior to the visitor?
I'm looking forward to your ideas.
Best
Nils