silverstripe shortcode return dynamic template - content-management-system

I followed this instruction to be able to include a variable in the Content Field (HTMLEditor) of a Page - so that the variable can be replaced with other content:
http://www.balbuss.com/mini-introduction-to-shortcodes/
I want to display a list of dataobjects within the $Content.
Sadly the DummyHandler in the instruction is static. So I canĀ“t access the Controller in it, to let him do something (generate the list.)
Is there a solution to access the controller in a static function or maybe is there another better way to put a variable in the $Content.
Thx,
Florian

Controller::curr() is probably what you are after?
To use in conjunction with Controller::hasCurr(), as no controller would mean an error when using Controller::curr()
See https://github.com/silverstripe/sapphire/blob/3.0/control/Controller.php#L384

Related

Modify all text output by TYPO3

I would like to create a "cleanup" extension that replaces various characters (quotes by guillemets) in all kinds of textfields in TYPO3.
I thought about extending <f:format.html> or parseFunc, but I don't know where to "plug in" so I get to replace output content easily before it's cached.
Any ideas, can you give me an example?
If you don't mind regexing, try this:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['cleanUpQuotes'][] = \NAMESPACE\Your\Extension::class;
Insert it into ext_localconf.php and this part is done.
The next step is the class itself:
public function cleanUpQuotes(TypoScriptFrontendController $parentObject)
{
$parentObject->content = DO_YOUR_THING_HERE
}
There also is another possibility which could replace any strings in the whole page - as it operates on the rendered page (and not only on single fields).
You even can use regular expressions.
Look at my answer -> here

How do I access GET/POST from a view helper?

I have a custom content element which uses a view-helper that inherits from link action. I want to use specific CSS when this link is "active". One way to do this would be to read _GET and check for link variables. Can I access _GET in a sane way from a view-helper? Or is there a better way?
Maybe this is impossible because the output of the view-helper will be cached...
I could of course access $_GET directly, but will this work with RealUrl?
Of course you can, the same way as you would do it within controller:
$fooInGet = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('foo');
$barInPost = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('bar');
$zeeAnywhere = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('zee');

Prestashop - variables not accessible in header.tpl-$category class not available

I am currently learning template variables and trying to understand how they work and what they mean.
I've done a test on {$category->id_cms_category}, which I put in cms.tpl and I get a result 9, but when I put this in header.tpl or blockcms.tpl (left column), there is no results, it's blank.
Can somebody please explain how this works and how I can get the same result in different .tpl file?
I think the question is really how to assign $category class to for example header.tpl. Is it something to do with controllers?
Why can't I use certain variables everywhere? How does this work? I would be very happy if somebody explain this.
I am also still learning smarty.
Unfortunately you're hitting a common problem with smarty, and particularly how it's implemented within Prestashop.
Smarty variables are very much limited in scope within Prestashop and their scope is determined by which point the portion of code they are assigned in is run. In the case of {$category->id_cms_category} it is assigned within the CMSController at the point in which the main content (important stuff in the middle) is rendered, and so will be available within cms.tpl as you have demonstrated.
The reason it isn't available in the left column or in the header is due to the order in which each of these sections are rendered. This will be:
a) Header (top of page rather than the html header block specifically), then
b) Left Column, then
c) "Main" Content, then
d) Right Column, then
e) Footer
You should find that if you were to reference it in the right column or the footer of the page, then magically it will be available to you (on CMS pages only of course as we're relying on the CMSController being run and assigning it a value).
If you need to reference things like the cms category within the header of the page (maybe to set a highlight on horizontal navigation) then you're going to need to fetch the value and assign it to smarty yourself. You can do this in one of two ways:
1) Write a module which is hooked into the header and assign your variable there
2) Override the FrontController class and assign the smarty variable there (e.g. in the init function)
An example of 2) which you could try is to create a file /override/classes/FrontController.php containing:
<?php
class FrontController extends FrontControllerCore
{
function init() {
parent::init();
$id_cms_category = (int)Tools::getValue('id_cms_category');
$id_cms_page = (int)Tools::getValue('id_cms');
self::$smarty->assign(array(
'my_cms_category_id' => $id_cms_category,
'my_cms_page_id' => $id_cms_page
)
);
}
}
The above should allow you to display {my_cms_category_id} and {my_cms_page_id} anywhere in your theme (because we're setting the smarty variables before everything else is rendered). For a non-cms page they should both be 0, my_cms_category_id should be set non-zero on cms category pages, and {my_cms_page_id} should be non-zero when on a specific cms page.
Hope this goes some way to making it a little clearer!

Line breaks in Zend Navigation Menu labels

I have a need to create a <br/> tag in the display label for a menu item generated using Zend_navigation, but don't seem to be able to find a way to do so.
My navigation item is defined in the XML config as:
<registermachine>
<label>Register your Slitter Rewinder</label>
<controller>service</controller>
<action>register</action>
<route>default</route>
</registermachine>
I want to force a tag in the output HTML between 'your' and 'slitter', such that it appears on two line as below:
Register your
Slitter Rewinder
However, I can't seem to do it. obviously using in the XML breaks parsing, and using html entities means that the lable is displayed as:
Register your <br/>Slitter Rewinder
Has anyone had experience of this that can offer advice?
Thanks in advance!
there is no such option built-in you have to use a partial
$partial = array('menu.phtml', 'default');
$this->navigation()->menu()->setPartial($partial);
echo $this->navigation()->menu()->render();
http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation.menu
you may also try a hack with <label><![CDATA[Menu label<br/>Second line]]></label>
I found a (hacky) solution:
I updated my navigation.xml to use {br} tokens wherever a <br/> tag is required, and then amended the base Zend/View/Helper/Navigation/Menu.php file as follows:
within htmlify function, changed
$this->view->escape($label)
to
str_replace("{br}", "<br/>", $label)
I could (and probably will) override the Zend Library Menu View Helper with my own at some point, but this at least cover it for now.
there is a escapeLabels boolean used to convert html tags and it's true by default.
You can set your navigation like this
$this->navigation()
->menu()
->escapeLabels(false)
->...
http://framework.zend.com/apidoc/2.0/classes/Zend.View.Helper.Navigation.Menu.html#escapeLabels

Get form field value via module [VBA]

I have a program built with VBA, in access.
I have a form with the field chDate and I need to get the value of the field in a module file named Global (not class module).
I tried to access it but I think I get empty value, string. not error.
I'm no expert with VBA, its new to me (I have experience with VBS).
Can someone please help me and tell me how can I access the value of a form field via module file?
Thanks!
If you can provide some sample code, it might help us in trying to get you a solution.
Here's what might work:
Dim an object as an instance of your form, and set the instance to a new instance. These two lines will do that (assuming the form is called frmForm)
Dim theForm as frmForm
Set theForm = new frmForm
then Show that Form:
theForm.show
The form will get the focus, so you can populate the fields. At that point, once the form is hidden, your code should be able to pull the field as such:
var1 = theForm.txtFormField.Text
However, if you unload the form in code, all variables directly tied to the form will be lost. In that case, you might want to follow Oneide's example, and set a global variable to the value of the form field. You can do this in one of the form's event handlers.
Let me see if I can recall my Access days. In your global module you should access the form field be prefixing the form name i.e.
var1 = Form1.txtFirmField.Text
As far as I know, you're trying to get the data the wrong way.
Anytime you would try to get your form data, from a standard module, your form probably will already be closed or, if you're not opening it as a restricted window, the value will not be ready yet.
Anyway, if you could get pass through all the difficulties above, you're probably coding in a not standard / right way.
Remember that VBA is an event driven language, and you would be better using it's strenghts rather than fighting against them.
As a final word, if this is just a casual coding, I suggest you using a global variable and make de Code Behind Form have set it up on control's change event.
If you're not sure what I mean, please leave a comment and I'll try to explain it better.
And, if you don't mind, let us know more about your starting code to get better answers.