drupal template.php not using tpl file - templates

I have a code which works on one server but not on the other. Basically we have written a template file which should be used if URL is discussion_forum but it shows page not found.
/* discussion forum templates */
$querystring=$_GET['q'];
echo $querystring; // THIS PRINTS page-not-found
$querystring=explode('&',$_GET['q']);
if(!isset ($vars['node']) && $querystring[0]=='discussion-forum'){
$vars['template_files'] = array();
$vars['template_files'][] = 'page-discussion_forum';
}
if (!isset ($vars['node']) && $querystring[0]=='discussion_forum_answer') {
$_SESSION['question_id']=$querystring[1];
$vars['template_files'] = array();
$vars['template_files'][] = 'page-discussion_forum_answer';
}
if(!isset ($vars['node']) && $querystring[0]=='discussion_forum_search'){
$vars['template_files'] = array();
$vars['template_files'][] = 'page-discussion_forum_search';
}
when I give page-not-found in place of discussion-forum in $querystring[0]=='discussion-forum'. It shows the the page properly. Don't know whats happening here. Its working fine on other servers.

To add custom tpl I usually add the theme suggestions in the preprocess node.
$vars['theme_hook_suggestions'][] = 'node____'.$vars['view_mode'];
So yours should be
function THEME_preprocess_node(&$vars, $hook)
$vars['theme_hook_suggestions'][] = 'page-discussion_forum_search';
}
It would help if you identify which version of drupal are you using because some of these things change between versions.

Related

Magento 2.3.3 dashboard keeps loading

I have installed latest version of magento in my localhost.
After login to admin panel dashboard keeps loading.
Here is the image-
Please help to solve this error.
First Go to magento root directory then :
vendor/magento/framework/view/element/tempalate/file/validator.php (dont exactly copy this url just follow this path)
open this file using any editor and change this line
$realPath = $this->fileDriver->getRealPath($path); //you can comment this out
with this one
$realPath = str_replace('\\','/',$this->fileDriver->getRealPath($path));
then goto to
app/etc/di.xml
and search for view_preprocessed
you will find a whole line like this :
Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink
and change the Symlink with Copy
Magento 2.3
go to \lib\internal\Magento\Framework\View\Element\Template\File
go to the function isPathInDirectories and replace the function with following
protected function isPathInDirectories($path, $directories)
{
if (!is_array($directories)) {
$directories = (array)$directories;
}
//$realPath = $this->fileDriver->getRealPath($path);
$realPath = str_replace('\\','/',$this->fileDriver->getRealPath($path));
foreach ($directories as $directory) {
//$realDirectory = $this->fileDriver->getRealPath($directory);
$realDirectory = str_replace('\\','/',$this->fileDriver->getRealPath($directory));
if ($realDirectory && 0 === strpos($realPath, $realDirectory)) {
return true;
}
}
return false;
}
go to app/etc/di.xml then search for view_preprocessed
you will find a whole line like this :
Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink and change to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
#1. go to vendor/magento/framework/View/Element/Template/File/Validator.php#
#2. go to the function isPathInDirectories and replace the function with following:#
protected function isPathInDirectories($path, $directories)
{
if (!is_array($directories)) {
$directories = (array)$directories;
}
//$realPath = $this->fileDriver->getRealPath($path);
$realPath = str_replace('\\','/',$this->fileDriver->getRealPath($path));
foreach ($directories as $directory) {
//$realDirectory = $this->fileDriver->getRealPath($directory);
$realDirectory = str_replace('\\','/',$this->fileDriver->getRealPath($directory));
if ($realDirectory && 0 === strpos($realPath, $realDirectory)) {
return true;
}
}
return false;
}
#3. go to app/etc/di.xml then search for view_preprocessed
you will find a whole line like this :
Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink and change to
Magento\Framework\App\View\Asset\MaterializationStrategy\Copy #

How to add hyperlink using templateprocessor (PHPWord Library)

I want to replace email variable into a hyperlink using template processor and I have used two way to solved this issue but didn't work and here is our below code for replacing email variable into hyperlink but when I used setValue or setComplexValue function for replacement value then document is corrupted.
We have tried below two scenarios for adding hyperlink but didn't work for us.
1. First Way
$pw = new \PhpOffice\PhpWord\PhpWord();
$section = $pw->addSection();
$textrun = $section->addTextRun();
$textrun->addTextBreak(2);
$section->addLink('mailto:demo1#gmail.com?subject=DEMO','demo1#gmail.com', array('color' => 'FF0000', 'underline' =>
\PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
$fullXml = $objWriter->getWriterPart('Document')->write();
$templateProcessor->setValue($var, $this->getBodyBlock($fullXml));
2. Second Way
$pw = new \PhpOffice\PhpWord\PhpWord();
$section = $pw->addSection();
$convertResult = 'demo1#gmail.com';
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $convertResult, false,false);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
$fullXml = $objWriter->getWriterPart('Document')->write();
$templateProcessor->setValue($var, $this->getBodyBlock($fullXml));
protected function getBodyBlock($string) {
if (preg_match('%(?i)(?<=<w:body>)[\s|\S]*?(?=</w:body>)%', $string, $regs)) {
return $regs[0];
} else {
return '';
}
}
Please help us thank in advance.

Backend Layout in TS file in TYPO3 CMS 7.6.18 how to get it working?

To be able to use different templates in a TYPO3 CMS 7.6.18 setup. I include a pageTSConfig.ts file with a backend layout looking like this. (see also this pastebin: https://pastebin.com/BcYKrYKh and this how it looks like in the TYPO3 object browser: https://pastebin.com/LVXqNUZC
### Backend Layouts #####
mod.web_layout.BackendLayouts{
1 {
title = Standaard Layout
config {
backend_layout {
colCount = 2
rowCount = 1
rows {
1 {
columns {
1 {
name = linker_inhoud
colPos = 1
}
2 {
name = midden_inhoud
colPos = 0
}
}
}
}
}
}
}
}
Since the BE-Layout is done with a file, in my TSconfig.ts I have added pagets__0 to it like the manual mentioned. Still this is not working. What Am I missing here? This is a part of the TSconfig I have in place here is the complete config:
page.10.file.stdWrap.cObject = CASE
page.10.file.stdWrap.cObject {
key.data = levelfield:-1, backend_layout_next_level, pagelayout, slide
key.override.field = pagelayout
default = TEXT
default.value = fileadmin/templates/index.html
pagets__0 = TEXT
pagets__0.value = fileadmin/templates/index.html
pagets__1 = TEXT
pagets__1.value = fileadmin/templates/layouts/small_header_page.html
pagets__2 = TEXT
pagets__2.value = fileadmin/templates/layouts/alternatieve_pagina.html
}
All to be included with:
There is a difference between "backend_layout", which is a the name of a real database field that can be fetched by "levelfield" and "pagelayout", which is a kind of virtual field to get rid of the "levelfield" approach.
https://docs.typo3.org/typo3cms/TyposcriptReference/DataTypes/Gettext/Index.html#pagelayout
key.data = pagelayout
should do the whole job for you and only in this case you can use stuff like
pagets__x
to access the actual layout.
So your code should either be:
page.10 = FLUIDTEMPLATE
page.10.file.cObject = CASE
page.10.file.cObject {
key.data = pagelayout
default = TEXT
default.value = fileadmin/templates/index.html
pagets__0 = TEXT
pagets__0.value = fileadmin/templates/index.html
pagets__1 = TEXT
pagets__1.value = fileadmin/templates/layouts/small_header_page.html
pagets__2 = TEXT
pagets__2.value = fileadmin/templates/layouts/alternatieve_pagina.html
}
or it should be
page.10 = FLUIDTEMPLATE
page.10.file.cObject = CASE
page.10.file.cObject {
key.data = levelfield:-1, backend_layout_next_level, slide
key.override.field = backend_layout
default = TEXT
default.value = fileadmin/templates/index.html
1 = TEXT
1.value = fileadmin/templates/layouts/small_header_page.html
2 = TEXT
2.value = fileadmin/templates/layouts/alternatieve_pagina.html
}
But not a mix of both approaches.
Before I tell you what might be wrong with your code, let me explain you a few things.
You have placed your templates in the fileadmin directory. This is not the place where to put these files any longer, because the fileadmin is a public place for resources like images, videos or documents. It might be available for every backend user in the filelist and the editor should not be able to edit the template in any case. The suggested way to handle your templates is to put them into an own extension that can be installed via the extension manager.
In your pastebin snippets, there is a line with userFunc = tx_templavoila_pi1->main_page, you may mixing up stuff in your installation and don't want to use FLUIDTEMPLATE alongside templavoila, because it could be confusing what rendering method is used for what stuff on your page. Better stick to templavoila or Fluid for the entirety of the TYPO3 installation.
Now, you have these lines in your TypoScript:
key.data = levelfield:-1, backend_layout_next_level, pagelayout, slide
key.override.field = pagelayout
There is no field pagelayout in the pages records. The field you rather want to address is backend_layout.

Get Returned text from ScriptManager(javascript) - INDESIGN SDK Plugin

I am using javascript inside my Plugin for Indesign CS6.
It is working fine.
But I need the return value from my javascript code now inside my c++ code.
I am using this site as reference:
https://blogs.adobe.com/indesignsdk/running-a-script-from-an-indesign- plug-in/
I need something like that:
scriptRunner->RunScript("function xpto(){return 'Hello World';};xpto()", params);
// fake method
const char *string_return = scriptRunner->getReturnCode();
are there something like that on scriptManager?
ps: it is not a indesign server. I put this tag because this site do not let me create a new tag...
Best Regards,
Use RunScriptParams::QueryScriptRequestData() .
From the SDK documents:
Query the IScriptRequestData that is used to pass arguments and return
the result.
The key is to get the iScript object from the 'RunScriptParams' object after the script has run. Then is it straight forward. Here is some sample code:
RunScriptParams params(scriptRunner);
IScriptRequestData* requestData = params.QueryScriptRequestData();
params.SetUndoMode(RunScriptParams::kFastUndoEntireScript);
if (scriptRunner->RunScript(script,params) != kSuccess) return NULL;
IScript *iScript = params.QueryTarget();
int resultsCount = requestData->GetNumReturnData(iScript);
PMString resultString;
if (resultsCount > 0) {
ScriptReturnData resultOne = requestData->GetNthReturnData(iScript,0);
ScriptData scriptReturnOne = resultOne.GetReturnValue();
scriptReturnOne.GetPMString(resultString);
}
The return value is in resultString.

Windows Phone 7 Consuming Webservice WSDL

Ok I have written some basic generic webservices before but I have never tried to consume a 3rd party one.
The one I am trying to consume is
http://opendap.co-ops.nos.noaa.gov/axis/webservices/predictions/wsdl/Predictions.wsdl
I am not getting any results back from this what so ever and cannot figure out why.
More odd is it is not even reaching PredictionsClient_getPredictionsAndMetadataCompleted when I put a break point in the code it doesn't even reach it.
Any suggestions would be greatly appreciated
public void Bouy(double meters)
{
PredictionService.Parameters PredictionParams = new PredictionService.Parameters();
PredictionService.PredictionsPortTypeClient PredictionsClient = new PredictionService.PredictionsPortTypeClient();
GeoCoordinateWatcher gc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
//gc.Position.Location.Latitude, gc.Position.Location.Longitude
GeoCoordinate myLocation = new GeoCoordinate(27.931631,-82.802582);
foreach (var bl in BouyLocation.GetAll())
{
GeoCoordinate otherLocation = new GeoCoordinate(bl.Lat, bl.Lon);
PredictionParams.beginDate = DateTime.Now.ToString("yyyyMMdd");
PredictionParams.endDate = DateTime.Now.AddDays(1.0).ToString("yyyyMMdd");
PredictionParams.stationId = bl.LocationID;
PredictionParams.timeZone = 0;
PredictionParams.unit = 1;
PredictionParams.dataInterval = 6;
PredictionsClient.getPredictionsAndMetadataCompleted += new EventHandler<PredictionService.getPredictionsAndMetadataCompletedEventArgs>(PredictionsClient_getPredictionsAndMetadataCompleted);
PredictionsClient.getPredictionsAndMetadataAsync(PredictionParams);
double mymeters = myLocation.GetDistanceTo(otherLocation);
if (mymeters < meters)
{
TextBlock DynTextBlock = new TextBlock
{
Name = "Appearance" + bl.LocationID,
Text = bl.LocationName + PredictionResult,
TextWrapping = System.Windows.TextWrapping.Wrap,
Margin = new Thickness(12, -6, 12, 0),
Style = (Style)Resources["PhoneTextSubtleStyle"]
};
DynamicAppearance.Children.Add(DynTextBlock);
this.nearByLocations.Add(new BouyLocationModel() { LocationName = bl.LocationName, LocationID = bl.LocationID, Lat = bl.Lat, Lon = bl.Lon });
}
}
var test = nearByLocations;
}
void PredictionsClient_getPredictionsAndMetadataCompleted(object sender, PredictionService.getPredictionsAndMetadataCompletedEventArgs e)
{
string err = e.Error.ToString();
PredictionResult = e.Result.ToString();
}
Loooking at the code you have here I think that you have used the importing of a ServiceReference to auto build the classes for you?
Unfortunately I have found that this is rather temperamental on WP7 and the only way I actually got it to work was when I connected it to a Microsoft WCF service. Connecting to anything else just doesn't work.
If you do google searches there are various pages talking about the fact it doesn't work and ways around it (which I couldn't get to work).
However, there are ways around it but it isn't as simple as the auto-generated stuff. Basically you do things manually.
Although there are other ways to manually create the web service what I did was follow the information in the following which worked well: http://zetitle.wordpress.com/2010/10/14/using-reactive-extensions-with-webrequest/
You will need to parse the response yourself but XML to LINQ works really well for this.
Hope that helps, or maybe someone will have the solution as it is something I am interested in knowing how to get working too