I am trying to display a custom page the same as my search results page by re-using the theme functions and pre-processors built into the search module.
With an empty Drupal cache this works beautifully. I simple call
theme('search_results', $results, 'node' );
with a correctly popuated results array, and I get back formatted markup.
Great.
However, when the cache is not clear, the search module is not available and so the theme() call goes nowhere and returns an empty string.
I've tried drupal_load('module','search') which makes the module file available, but does not intialize its hook_theme.
Fixed it with the following:
function_exists('search_theme') or drupal_load('module','search');
function_exists('template_preprocess_search_results') or module_load_include('inc','search','search.pages');
I don't like it though.
For theming standard search results use these:
http://api.drupal.org/api/drupal/modules--search--search-result.tpl.php/6
http://api.drupal.org/api/drupal/modules--search--search-results.tpl.php/6
Related
I have an application in TYPO3 CMS. It has an extension test_extension that has a controller and an action. This action should return some JSON.
class TestRequestController extends ActionController
{
public function testAction(): void
{
echo json_encode([
'test' => 123
]);
}
}
I want to be able to request this action via Postman. How can I do that? TYPO3 version - 8.7. Thanks in advance!
Creating Links
Usually extbase-extensions are created with the help of the extension extension_builder. This extension creates by default templates and links to open list- and detail-view.
It's possible to add additional actions and to create according links.
Also the usage of the templates is not required and your way to return the result of the action without usage of a template is possible.
The logic of the links is this, I break the parts down in single lines:
tx_extension_plugin[controller]=TestRequest
tx_extension_plugin[action]=test
There are still more parameters commonly used like id or search, but it's also possible to define individual parameters.
In your case the listed parameters seem to be sufficient and the link would look like this now:
www.example.com/?id=123&tx_extension_plugin[controller]=TestRequest&tx_extension_plugin[action]=test
for the extension news this would look like this, this is with your parameter-values which are not available in news. This example shows only how the extension-related part is handled (tx_news_pi1):
www.example.com/?id=123&tx_news_pi1[controller]=TestRequest&tx_news_pi1[action]=test
id is for the page here and not a parameter for your extension, else id had to look like this tx_extension_plugin[id]=123. So all extension related parameters have the form tx_extension_plugin[parameter]=value.
While it's possible to create those links with the API, it's easier to create them with the view helpers for the fluid templates. Note that sometimes an hash is added at the end, like this example: &cHash=1234567890.
The cHash-value you can't create without viewHelper or API, so the knowledge about the parameters and the other values is not enough to create the links.
Calling the link
Most often links are directly called by the browser and visible in the URL-bar. But sometimes and in your case you might call the links by AJAX, so that the json is loaded without being directly shown to the user.
It's also possible to wrap the json in script-tags, so that it's every time loaded when the whole page is called, it's not dynamic then and without AJAX it can't adjust to some user-interaction without loading a whole page again.
AJAX responses can be realized in many ways in TYPO3, the most easy one is to define a special page-type and a special page in the pagetree for it. On this page you add the plugin of your extension to return the json. This "Ajax-page" has to be configured to have the correct header for Json and must not return anything else but the JSON, so all HTML-Output has to be disabled.
Well, I am developing a plugin a and I need to display some stuff from my plugin when TYPO3 page load.
Is there some function how to hook action, like in WordPress when page loads than plugin will execute some controller method? Then this controller will produce some output a HTML, which I would like to dispaly in frontend page. Specially I would like display custom script in the head. So the script should be like this <head>...<script>my content</script>...</head>
Ok, what you probably want to do is to develop a so-called TYPO3 extension - that's what plugins/add-ons are called in TYPO3 (which is the term you will likely find google results for).
To get started fast you can try the TYPO3 extension builder (https://docs.typo3.org/typo3cms/extensions/extension_builder/) - which can generate a skeleton extension for you.
For more information you can also have a look at https://docs.typo3.org/typo3cms/CoreApiReference/latest/ExtensionArchitecture/Index.html which explains the concepts in far more detail.
Additional information is available in https://docs.typo3.org/typo3cms/ExtbaseFluidBook/Index.html
in TYPO3 there is something named plugins, but you should differ to the meaning in other context.
first TYPO3 is a CMS which content is structured in a hierarchical tree of pages. These pages are the basis for navigation. and each page contains individual contentelmenents (CE).
As Susi already told: add ons to TYPO3 are in general 'extensions' which could extend(!) the functinality of TYPO3 in different ways. one way is the definition of (TYPO3-)Plugins. These are special ContentElements which enable to show special information.
While normal CEs have all the information what to show in the record (e.g. Text & Image), plugins can be more flexible.
typical examples are: show a list of records OR one record in detail.
These Plugins can be controlled with typoscript or the plugin-CE could have additional fields to hold information what to display.
For detailed information how a plugin is defined consult the links given by Susi.
And be aware: for security reasons it is not possible to just execute a plain PHP file to echo any output. You need to register your plugin using the API, build your output as string and return the generated HTML as string to the calling function. For beginners the ExtensionBuilder will help you to generate a well formed extension which uses the API to register and output your data.
OK guys, thanks for your answers, but it was not very concrete. I found this solution, is not the best one, but it works! If anybody has better please share.
At first, you have to make a file for the class which will be called from the hook at location /your-plugin-name/Classes/class.tx_contenthook.php. Filename have to have this pattern class.tx_yourname.php Inside we will have a code with one method which will be called by the hook.
class tx_contenthook {
function displayContent(&$params, &$that){
//content of page from param
$content = $params['pObj']->content;
//your content
$inject = '4747474747';
// inject content on
$content = str_replace('</body>', $inject. '</body>', $content);
// save
$params['pObj']->content = $content;
}
}
And next, we have to call it on the hook. So Let's go to /your-plugin-name/ext_localconf.php and add there these two lines, which makes a magic and handles also caching.
// hook is called after caching
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output'][] = 'EXT:' . $_EXTKEY . '/Classes/class.tx_contenthook.php:&tx_contenthook->displayContent';
// hook is called before caching
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-all'][] = 'EXT:'. $_EXTKEY .'/Classes/class.tx_contenthook.php:&tx_contenthook->displayContent';
I hope this will help those who struggling with typo3.
I'm not so familiar with Smarty. In the code I'm exploring, I have found such construction:
...
Can't understand, how does that url construction work. Looks like it is some custom method (or whatever it's called) in our project. But the project is quite large and I can't find it's definition just by word url.
Where to look for? What can it be?
url - is a Smarty custom plugin, which you can find in smartys' plugin folder. a.category, a.subcategory, a.nice_url: are params that passed to the url.
The following:
{url ...}
url is the custom Smarty Function. You can find it in Smarty plug-in directory or in a file that keeps all functions (if there is one) for your project.
In case you want to find the ends, just search through your whole web-site directory for the following content:
smarty_function_url
It must be found anyway, because it's the only way you can register custom Smarty function.
EDIT 1:
As correctly stated by sofl, if the plug-in is registered dynamically using registerPlugin method:
$smarty->registerPlugin("function","url", ...)
then you would have to search for the following instead:
registerPlugin("function","url"
or
registerPlugin(" function ", " url "
If it still doesn't work just try searching for ->registerPlugin, I think there is no other options left after all and you will find it!
I've been making a Joomla module. I've mostly been successful, but I have one question: how do you get the image_fulltext variable to contain the following?
{"image_intro":"","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/sampledata\/parks\/landscape\/800px_cradle_mountain_seen_from_barn_bluff.jpg","float_fulltext":"","image_fulltext_alt":"Konsultasi belajar","image_fulltext_caption":""}
This functionality can be found inside the PHP library see json_encode and json_decode.
I am brand new at writing Wordpress plugins, so to start I am trying to create a simple one that just modifies a string. I wrote the script a while ago, and know that it functions. But to use it for Wordpress I want to apply it to the post titles. When I replaced the string with the function "get_the_title()" it returns a white screen. I stripped it down to:
function display_title() {
echo get_the_title();
}
add_action('the_title', 'display_title');
This still returns a white screen. So I figure it must be the "get_the_title()" function. Can anybody explain to me why this doesn't work, and maybe a different way to retrieve the title string?
As John says the_title is a filter rather than an action hook, although your function will be called regardless of whether you register it using add_filter or add_action.
Your problem is that with filters your function is expected to return a value (normally a modified version of the argument passed). So, to modify the title using this filter you should do something like this:
function display_title($title) {
$title .= '!'; // Do something with the title string here
return $title;
}
add_filter('the_title', 'display_title');
Well, for one thing, 'the_title' isn't an action, it's a filter. So that function is never firing. So it's not the fault of that function, it is probably something else. I would suggest reading up on the plugin api and learning the difference between actions and filters. Filters are specifically designed to do what you want in a simple way:
http://codex.wordpress.org/Plugin_API/