Pretty straight forward question:
I have page--front.tpl and page.tpl template pages in use in a drupal 7 site. However, I'd like to use page-front.tpl on one other page. Is this possible or do I need to create another .tpl page to do this.
The site I'm working on is split into two sections, it's essentially two seperate websites that you can flip between whether your a consumer or business owner. So I want to use the front.tpl template for the home page of each site.
Cheers.
You can add theme_preprocess_page function to your theme's template.php file and then add your template name in templates suggestions list.
function mytheme_preprocess_page(&$vars) {
// you can perform different if statements
// if () {...
$template = 'page__front'; // you should replace dash sign with underscore
$vars['theme_hook_suggestions'][] = $template;
// }
}
EDIT
If you want to specify template name by path alias, you could write code like this:
function phptemplate_preprocess_page(&$variables) {
if (module_exists('path')) {
$alias = drupal_get_path_alias($_GET['q']);
if ($alias != $_GET['q']) {
$template = 'page_';
foreach (explode('/', $alias) as $part) {
$template.= "_{$part}";
$variables['theme_hook_suggestions'][] = $template;
}
}
}
}
Without this function you would have the following node template suggestions by default:
array(
[0] => page__node
[1] => page__node__%
[2] => page__node__1
)
And this function would apply to your node the following new template suggestions.
Example node with node/1 path and page/about alias:
array(
[0] => page__node
[1] => page__node__%
[2] => page__node__1
[3] => page__page
[4] => page__page_about
)
So after that you can use page--page-about.tpl.php for your page.
If you want to apply page--front.tpl.php to your let's say node/15, then in this function you can add if statement.
function phptemplate_preprocess_page(&$variables) {
if (module_exists('path')) {
$alias = drupal_get_path_alias($_GET['q']);
if ($alias != $_GET['q']) {
$template = 'page_';
foreach (explode('/', $alias) as $part) {
$template.= "_{$part}";
$variables['theme_hook_suggestions'][] = $template;
}
}
}
if ($_GET['q'] == 'node/15') {
$variables['theme_hook_suggestions'][] = 'page__front';
}
}
This would give you the following template suggestions:
array(
[0] => page__node
[1] => page__node__%
[2] => page__node__1
[3] => page__page
[4] => page__page_about
[5] => page__front
)
The highest index - the highest template priority.
Related
I want to edit a message, but it's only updated when i changed this message _id. Can someone provide me how to do it, here is my code:
const onSend = useCallback((messagesToSend = []) => {
if(editMessage != null){
setEditMessage()
const m = messagesToSend[0]
const newMessages = [...messages]
const index = newMessages.findIndex(mes => mes._id === editMessage._id);
console.log('index: ', index)
if(index > -1){
newMessages[index].text = m.text // => ***i only edit the text***
// newMessages[index]._id = uuid.v4() => ***this working if changed _id***
console.log('newMessages', newMessages[index]) // => ***new message changed it's text but the bubble not change when re-render***
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
setMessage(newMessages)
}
}else{
setReplyMessage()
appendMessage(messagesToSend)
}
})
It looks like you're using useCallback without a dependency array. This means that any dependencies that you rely on will be memoized and won't update when you run the function.
You should add messages, editMessage, and maybe setMessage and appendMessage, to the dependency array. Like so:
const onSend = useCallback(
(messageToSend = []) => etc,
[messages, editMessage, setMessage, appendMessage]);
That's the first thing I would try
ok i found problem, in MessageText the function componentShouldUpdate need modify a bit
I am trying to update a legacy php code (7.0) for php 7.4 >=
and one of the new features that I would like to use the new fn() => syntax, instead of function() use () {}
Unfortunately, I have hundreds of anonymous functions using CakePHP ORM like:
$query->matching('Tags', function ($q) {
return $q->where(['Tags.name' => 'CakePHP']);
});
Using php 7.4 >= could be:
$query->matching('Tags', fn($q) =>
$q->where(['Tags.name' => 'CakePHP'])
);
Sometimes using "use":
$query = $articles->find()->matching('Comments.Users', function ($q) use ($username) {
return $q->where(['username' => $username]);
});
php 7.4 >= (use is not needed):
$query = $articles->find()->matching('Comments.Users', fn ($q) =>
$q->where(['username' => $username])
);
Or using two or more params:
$query->where(function (QueryExpression $exp, Query $q) {
return $exp->eq('published', true);
});
But when you have more than one instruction, fn () cannot be used, for example:
$results->map(function ($row) {
$row['age'] = $row['birth_date']->diff(new \DateTime)->y;
return $row;
});
I would like to use notepad++ regex and replace in all files feature to execute a regex and replace all "possible" functions() for fn().
So, What REGEX could achieve this goal?
Find: function\s*\(([^\(\)]*)\)[^\{]*\{\s*return\s*([^;]*)\s*;\s*\}
Replace: fn\(\1\) => \2
question is very simple, is there a quick way to translate a preloaded list in db. For example list of towns/countries?
class SeedTownTable extends Seeder
public function run()
{
$town_list = array(
'Акко',
'Арад',
'Ариэль',
'Афула',
'Ашдод',
'Ашкелон',
'Бат-Ям',
'Бейт-Шеан',
'Бейт-Шемеш',
'Бейтар-Илит',
'Беэр-Шева',
'Бней-Брак',
'Герцлия',
'Гиват-Шмуэль',
'Кирьят-Малахи',
'Кирьят-Моцкин',
'Кирьят-Оно',
'Кирьят-Тивон',
'Кирьят-Хаим',
'Кирьят-Шмона',
'Кирьят-Ям',
'Кфар-Саба',
'Лод',
'Маале-Адумим',
'Маалот-Таршиха',
'Метула',
'Мигдаль-ха-Эмек',
'Модиин',
'Ход-ха-Шарон',
'Холон',
'Цфат',
'Эйлат',
'Эльад',
'Явне',
'Яффо'
);
foreach ( $town_list as $town ){
Town::create([
'name' => $town
]);
}
}
I made towns model with records without any backend controller.
And I want to translate this list.
thanks.
Add the translation to your data array and use setAttributeTranslated to add the translated version.
As mentioned in the Docs
// Gets a single translated attribute for a language
$user->getAttributeTranslated('name', 'fr');
// Sets a single translated attribute for a language
$user->setAttributeTranslated('name', 'Jean-Claude', 'fr');
Try
$town_list = array(
[
'name' => 'Town Name Default Lang',
'name-es' => 'Town Name in Spanish',
]
...
)
foreach ( $town_list as $town ){
$t = new TownModel();
$t->name = $town['name'];
$t->setAttributeTranslated('name', $town['name-es'], 'es');
$t->save();
}
I programmed a custom field plugin for Virtuemart 2.6.6, which show some parameters on the product page for example "size", and that parameter is a cart variable either.
A huge help was this article:
https://www.spiralscripts.co.uk/Joomla-Tips/custom-plugin-fields-in-virtuemart-2-2.html
And of course stackoverflow forum and factory default VM custom plugins.
Everything is working (the size is displayed in product details view, and in the cart, when you added the product to it) but one thing:
after sending the order the parameter has not displayed in the order details, so I don't know what size of product was bought.
I placed following functions into my plugin, but not solved my problem:
function plgVmOnViewCart($product, $row, &$html)
{
if (empty($product->productCustom->custom_element) or $product->productCustom->custom_element != $this->_name) return '';
if (!$plgParam = $this->GetPluginInCart($product)) return false ;
$html .= '<div class="parameterek_attributes">';
foreach ($plgParam as $attributes) {
foreach ($attributes as $k => $attribute) {
if ($k =='child_id') continue;
if ($k == 'custom_param_default3') $name = 'Veľkosť'; else $name = '';
$html .='<span class="parameterek_attribute"> '.$name.': '.JText::_($attribute).' </span>';
}
}
$html.='</div>';
return true;
}
/**
*
* shopper order display BackEnd
*/
function plgVmDisplayInOrderBE($item, $row,&$html)
{
if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return '';
if(!empty($productCustom)){
$item->productCustom = $productCustom;
}
$this->plgVmOnViewCart($item, $row,$html);
}
/**
*
* shopper order display FrontEnd
*/
function plgVmDisplayInOrderFE($item, $row,&$html)
{
if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return '';
$this->plgVmOnViewCart($item, $row,$html);
}
Into database table called #__virtuemart_order_items were saved values: something like:
{"357":"5"}
but it should be something like:
{"357":"size M"}
I see that the key function is GetPluginInCart($product), and when I printed out the $product->param in that function I've got this output, when I go through checkout process:
Array
(
[0] => Array
(
[parameterek] => Array
(
[custom_param_default3] => L
)
)
)
but after I finish the order and go into order details the $product->param has this value:
Array
(
[357] => 5
)
So I think, before I finish the order I have to somehow handle the
chosen product parameter and transform it into the correct form, but
I don't know how.
On the following site
https://dev.virtuemart.net/projects/virtuemart/wiki/Product_Plugins
I found a function:
plgVmOnViewCartOrder($product, $param,$productCustom, $row)
handel $param before adding it in the order
return $param;
but when I searched for the string "plgVmOnViewCartOrder" in the whole virtuemart installation, it was not found, so it means it is not launched (?)
If anybody could help me or send a fair documentation would be very good. Thank you!
I think, I solved my problem, what was:
in function plgVmOnDisplayProductVariantFE I made a mistake, I didn't use layout renderer, which generates an object $viewData with variable virtuemart_customfield_id.
Then in your plugin's layout, input field name has to be as follows:
<input
class="parameterekInput"
type="radio"
id="plugin_param['.$viewData[0]->virtuemart_customfield_id.']['.$this->_name.']['.$c.']"
name="customPlugin['.$viewData[0]->virtuemart_customfield_id.']['.$this->_name.'][custom_param_default3]"
value="'.$size.'" />
so the name attribute should be always:
customPlugin['.$viewData[0]->virtuemart_customfield_id.']['.$this->_name.'][whatever]
The right usage of plgVmOnDisplayProductVariantFE function is to use expression:
$group->display .= $this->renderByLayout('default',array($field,&$idx,&$group )
Here the whole function with the right expresion:
function plgVmOnDisplayProductVariantFE ($field, &$idx, &$group) {
if ($field->custom_element != $this->_name) return '';
$this->getCustomParams($field);
$this->getPluginCustomData($field, $field->virtuemart_product_id);
$group->display .= $this->renderByLayout('default',array($field,&$idx,&$group ) );
return true;
}
Now when I print_r -ing $product->param in function GetPluginInCart($product), I get this:
Array
(
[273] => Array //previously the key was Zero, now it is 273, value of virtuemart_customfield_id
(
[parameterek] => Array
(
[custom_param_default3] => L
)
)
)
...and now I'm glad, that I can move on in my project :)
I would like to return an array of string in my web services
I've tryed :
<?php
require_once('nusoap/nusoap.php');
$server = new soap_server();
$server->configureWSDL('NewsService', 'urn:NewsService');
$server->register('GetAllNews',
array(),
array('return' => 'xsd:string[]'),
'urn:NewsService',
'urn:NewsService#GetAllNews',
'rpc',
'literal',
''
);
// Define the method as a PHP function
function GetAllNews()
{
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
return $stack;
}
but it doesn't work. What is the correct syntax for that ?
Thanks in advance for any help
You first need to define a new type that describes an array of strings like so:
$server->wsdl->addComplexType(
'ArrayOfString',
'complexType',
'array',
'sequence',
'',
array(
'itemName' => array(
'name' => 'itemName',
'type' => 'xsd:string',
'minOccurs' => '0',
'maxOccurs' => 'unbounded'
)
)
);
Then you can use tns:ArrayOfString as the return type.
This site describes a nice way to return complex datatypes and receive it with C#: http://sanity-free.org/125/php_webservices_and_csharp_dotnet_soap_clients.html
When returning array of arrays, you might need a different configuration from Oliver. For example phfunc2php uses this technique in the nusoapcode.class.php file (https://github.com/sylnsr/pgfunc2php/blob/master/nusoapcode.class.php). The code it generates looks like so:
$server->wsdl->addComplexType(
'ArrayOfArrays','complexType','array','',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')));
and then the functions simply needs to return "tnsArrayOfArrays:
$server->register(
'sel_signon_id_by_uuid',
array('user_uuid' => 'xsd:string'),
array('return'=>'tns:ArrayOfArrays'),
The project mentioned above can compile working code for you, should you want to see this.