I am trying to use meta tags and description in cakephp 3. It is working so far, but I am facing the problem that I canĀ“t put it in the of my page, because my .ctp files are rendered in my default.ctp
So for example I have my menu, footer etc. in my default.ctp and my page for the faq is in the faq.ctp How can I push those
<?php
echo $this->Html->meta('description','enter any meta description here');
?>
metadescription in the head tag? Do I need a template language like smarty and use blocks?
In layout:
<?php
echo $this->Html->meta('description',$description);
?
in your faq.ctp or faq() method:
<?php
$this->set('description','enter any meta description here');
?
add this in your ctp file (there is NO echo )
<?php $this->Html->meta('description', 'some text here', ['block' => true]);?>
and this line into your layout
<?php echo $this->fetch('meta');?>
see also similar question with title: $this->set('title', 'Title Name'); not working in CakePHP 3.x
Related
Ok, so I have a web app that uploads a file to the webserver. My input fields in my upload form include: type of upload (dropdown list), title, description, and the file to be uploaded, which is a PDF.
Once the PDF file is uploaded, the download link will appear in another page for the public to see. In addition, the title typed in the input field is the download link.
Now, I want to change my code. Instead of downloading it directly when the link is clicked I want it to open in a new tab, so the users can first look at the PDF file then download it from there.
Here are my codes.
Controller:
public function sendFile(){
$id = $this->request->params['pass'][0];
$staffup = $this->StaffUpload->find('first', array('conditions' => array('iduploads'=>$id)));
$this->response->file($staffup['StaffUpload']['dest'], array('download' => true, 'name' => $staffup['StaffUpload']['title']));
return $this->response;
}
The code above is the download function.
public function resources() {
$this->layout = 'website';
$this->set('staff_uploads', $this->StaffUpload->find('all', array('conditions' => array('type' => 'Resource'))));
}
The code above is the view wherein I show all uploaded files which type is Resources.
View:
<?php
foreach ($staff_uploads as $staff_uploads) {
?>
ul>
<li>
<?php
echo $this->Html->link($staff_uploads['StaffUpload']['title'], array('controller' => 'websites', 'action' => 'sendFile', $staff_uploads['StaffUpload']['iduploads']));
?>
</li>
</ul>
<?php
}
?>
The code above shows the view.
So yeah, back to the question. I want to change the download link to a link in which when clicked, will show the PDF file in a new tab. How do I do that? And by the way, the codes posted above are all working properly. I just want to change my code so that it will be viewed in a new tab when clicked.
Thank you!
According to the docs:
echo $this->Html->link(
'Enter',
'/pages/home',
array('target' => '_blank')
);
I am currently building a wordpress theme. For the menu, I just want to display all the pages that are created in the order that they are created in (i.e. I don't want users to have to go into the 'menu' section of the site and create their own).
I tried using wp_page_menu and this worked HOWEVER I need to add a walker class to expand the functionality, which you can't do with this function. So I need a way to display all my pages with using wp_nav_menu as my code - is there a way to do this?
Here is my code currently:
<nav id="nav">
<?php wp_nav_menu( array( 'walker' => new Clapton_Nav_Walker ) ); ?>
</nav>
Try this
functions.php this below code register a menu for use
<?php register_nav_menu( 'main_menu', 'Primary Menu' ); ?>
// remove <?php ?> tags if it already there
index.php or wherever you want, below code output the menu
<?php wp_nav_menu( array( 'theme_location' => 'main_menu','walker' => new Clapton_Nav_Walker ) ); ?>
Build menu in WordPress Dashboar -> Appearance -> Menus -> Manage Locations
I am a Cakephp beginner
I am creating breadcrumbs from my website, I am not sure what is the difference between using HTML helper and Breadcrumb helper, Html helper seems easier to use, but it seems like I have to add each crumb to each page manually, please correct me if i am wrong.
When I was trying to use the Html helper, I put
<?php echo $this->Html->getCrumbs(' > ', array( 'text' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index'), 'escape' => false)); ?>
in my index.ctp
then, i put
<?php $this->Html->addCrumb('Add customer', 'Customers/add'); ?>
in add.ctp
the breadcrumb "Customer" appears on the index.ctp, but when i go to the add.ctp page, no breadcrumb is shown.
I tried putting
echo $this->Html->getCrumbs(' > ', 'Home');
in default.ctp, then the "Add customer" appears after the Home crumb
How can I make it so that, on the add.ctp , the breadcrumb shows like this:
Customers > Add customer
You should take a better look at the documentation in the cookbook, usually it's all there.
Steps are:
Create a place for cakePHP to display the breadcrubs in your layout template, not index.ctp using something like echo $this->Html->getCrumbs(' > ', 'Home');. You should find your default layout in View/Layout/default.ctp.
Add a trail in each page with something like $this->Html->addCrumb('Add customer', 'Customers/add'); for View/Customers/add.ctp
This is all done by the HTML helper, there isn't any different (official) breadcrumb helper.
I am moving my website to use cake php and before i would just have to include an image like this in my project print("<img class='custom' alt='' src='$dish_image' />"); as you can see I included the css class to be used. But now with cake php I am not sure how to achieve as my image tag looks like this
echo $this->Html->image($dishes['Dish'][0]['dish_image'], array("alt" => ""));
So i am not sure where to apply that custom css to it... The css is in a separate css file.
Any help would be appreciated/
This should do it:
<?php echo $this->Html->image($dishes['Dish'][0]['dish_image'], array(
"class" => "custom",
"alt" => ""
)); ?>
Good luck!
I have tried many times to use this plugin and I failed.
I am following documentation, but it does not work for me.
I am posting the simple code here, to know what wrong I am doing.
1-I put this plugin in this folder app/plugins
2- I add TinyMce helper to articles_controller
<?php
class ArticlesController extends AppController {
// good practice to include the name variable
var $name = 'articles';
// load any helpers used in the views
var $helpers = array('Html', 'Form','TinyMce.TinyMce');
/**
* index()
* main index page of the formats page
* url: /formats/index
*/
function index(){
// get all formats from database where status = 1
$articles = $this->Article->find("all") ;
$this->set('articles', $articles);
}
function admin_add() {
// if the form data is not empty
if (!empty($this->data)) {
// initialise the format model
$this->Article->save($this->data);
// set a flash message
$this->Session->setFlash('The Format has been saved');
// redirect
$this->redirect(array('action'=>'index'));
} else {
// set a flash message
$this->Session->setFlash('The Format could not be saved. Please, try again.','default', array('class' => 'flash_bad'));
}
}
}
?>
3- in the view file articles/admin_add.ctp I added the editor
// i think the problem in this code
<?php $this->TinyMce->editor(array(
'theme' => 'advanced'
)); ?>
<div class="formats form">
<?php echo $form->create('Article');?>
<fieldset>
<legend>Add a article</legend>
<?php
// create the form inputs
echo $this->Form->input('title');
echo $this->Form->input('content'); ?>
</fieldset>
<?php echo $form->end('Add');?>
</div>
<ul class="actions">
<li><?php echo $html->link('List Articles', array('action'=>'index'));?></li>
</ul>
You need to put tinymce files into your js assets
Then you have to add into section of your layout.
Then you'll need to init tinymce according to example provided on tinymce website (ex: full tinymce layout) and configure it according to your requirements.
I'd personally would not rely on such cake plugins, when actions required to get things working are not many and they are simple enough.