I'm rewriting wordpress site to yii2.
and I have to keep previous posts urls for some reasons!
They are somethings like that
https://example.com/blog-thenameofpost
So I created a Blog controller and I have this link in this way
https://example.com/blog/view?id=thenameofpost
I don't know how can I write a urlManager rule for doing that.
I just add this rules
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
and now this link
https://example.com/blog/view?id=thenameofpost
opens with something like it:
https://example.com/blog/thenameofpost
Are there any rules to open link with some thing like it https://example.com/blog/thenameofpost ?
If you want to create a rule for https://example.com/blog-thenameofpost you could add the following rule.
'blog-<id>' => 'blog/view',
The left part is what you will actually see in your address bar. You can use < > to indicate a parameter. So this rule will match anything that starts with blog- and then consider the part after that as the id param. The right part is where this request should be routed to. So this request will end up in the BlogController and call actionView($id), where $id will be set to the <id> part; thenameofpost in the case of the example URL.
The rule for https://example.com/blog/thenameofpost would be
'blog/<id>' => 'blog/view'
Additional info:
In the param part (left side) you can add additional info for matching the param. So <id:\d+> will only match digits, because of de \d+ part. For more info read the docs: http://www.yiiframework.com/doc-2.0/yii-web-urlmanager.html#$rules-detail
Related
The Gutenberg Handbook currently has a short entry for creating whole templates of blocks used e.g. for Custom Post Types or the like.
https://wordpress.org/gutenberg/handbook/templates/
It seems to be missing a comprehensive overview of the core/-Blocks though. Especially the available attributes are interesting here. Is there a reference-entry I am just missing?
To elaborate:
By playing around, I found out a few things. E.g. preformatted blocks do take the formatting of a php file like line breaks, indends and tabs, which makes them a bit sensitive..
array( 'core/preformatted', array(
'content' => 'Grundlegende Fakten:
Operator: Max Mustermann
Wo: City, Country
Wer: 99999 Kinder
Wieviel: 99999 Angestellte',
) ),
This does translate into:
(note that every tab or indent before later lines would have been taken over as well)
So - what other possibilities do i have to modify the 'content' and 'placeholder' attributes? Can I make use of the fact that they are arrays and insert selectors or other html like .. This does NOT work:
array( 'core/preformatted', array(
'content' => array('selector' => 'h1', 'content' => 'Does this do anything?'),
) ),
..But this DOES:
array( 'core/preformatted', array(
'content' => array('Does', 'this', 'do', 'anything?'),
) ),
And where can I find a comprehensive list of first order attributes, since e.g it's not always clear whether a core/block will take a 'text'-string or a 'content'-array and so on..
To partly answer my own question:
As mentioned in this git issue you can use
console.log(wp.blocks.getBlockTypes());
in the browser console after all the Gutenberg magic loaded (e.g. in the editor window of a post) to show all currently registered blocks, inluding their attributes.
Definitely a helpful tool!
Another Info-Source:
The Git-Project of Gutenberg holds all core blocks and their properties can be accessed by
Name-of-Block/index.js
Then find: const blockAttributes =
I am trying to create a Yii2 theme, & would like to set a variable that with scope of the entire views folder. For a single page theme I used...
$assetDir = Yii::$app->assetManager->getPublishedUrl(
'#vendor/path/to/assets/folder'
);
in index.php & I then I accessed it using...
<img src="<?= $assetDir ?>/img/image.jpg" alt="">
For partials I am able to pass that using...
<?= $this->render('_partial.php', ['assetDir' => $assetDir]) ?>
I am now wanting to do similar in a theme with multiple pages & cannot find how to do that without setting $assetDir in each page. I imagine it would be set in the main.php layout.
Use params array for this as stated in Sharing Data among Views.
The view component provides the params property that you can use to share data among views.
For example, in an about view, you can have the following code which specifies the current segment of the breadcrumbs.
$this->params['breadcrumbs'][] = 'About Us';
Then, in the layout file, which is also a view, you can display the breadcrumbs using the data passed along params:
<?= yii\widgets\Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
I have a table content to be emailed using a perl script. "background-color:#dddddd" doesn't seem to work in windows outlook. Email looks plain.
How to make my table look as i want?
Some emails decide also to not show html content, but this is not your case.
first I would suggest you to use (took from quickstart guide cpan)
use strict;
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => '"Xavier Q. Ample" <x.ample#example.com>',
From => '"Bob Fishman" <orz#example.mil>',
Subject => "don't forget to *enjoy the sauce*",
Content-Type => 'text/html';
],
body => "This message is short, but at least it's cheap.\n",
);
sendmail($email);
look at mail sender example, we will not be able to help you if you don't put some code as an example
I have a template that i was using for my project.
Look at the picture below:
This is when i am not using the kartikGrid. the dropdown menu running as well as the template want.
look at the image below:
this is when i use kartik, the dropdown menu not running anymore.
can some body tell me why it happen.
The template using different bootsrap version with kartik.
thaks.
Hope some body help me.
Imaginaroom, that did the trick for me thank you.
My top menu wasn't responding (direct link, or drop down menu) after kartik was used. I added an id to my menu widget and it did the trick.
echo Nav::widget([
'id' => 'topMenuID',
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
Manually assign different ids to all widgets, so there won't be any conflicts.
If you don't assign ids to widgets, yii gives them one automatically, but the problem occures when loading data with ajax or pjax, then Yii cannot know which ids are already used in the page.
Every widget in Yii2 has a property 'id' that you can assign in configuration array when calling a widget.
Add this code in layout or page that has problem:
$this->registerJs( "$(document).ready(function() { $('.dropdown-toggle').dropdown(); });", View::POS_END, 'ecommerceProductJs' );
I'm looking for some help regarding partials. I have created a partial for a menu on my site, but I would like to know whether I can add an additional class to a partial. More specifically, I am looking to assign an additional class to an li menu object so that I can indicate that the user is on that particular page.
Here is my code for the partial (I'm using HAML). It's named _menu.html.haml and it is located in the 'shared' folder.
.three.columns
%ul#nav
%li
%a{:href => "../pages/about"} About
%li
%a{:href => "../pages/careers"} Careers
%li
%a{:href => "../pages/contact"} Contact Us
%li
My code for the carrers.html.haml page is as follows:
code...
= render :partial => 'shared/menu'
more code...
I would like to add a .active_page class to the careers link located in the partial. This class changes the background image behind the text to indicate that the user is on a specific page. More specifically, I'd like it to look like so:
%li.active_page
%a{:href => "../pages/careers"} Careers
Is it possible to do this using partials?
The fact that you're using a partial doesn't change how you're able to use HAML, or ERB, or anything like that. If you want to add a class, yes, then just add .active_page on to an HTML tag. If it's a valid thing to do in HAML, then you can do it anywhere in a view, even if it happens to be a partial.
A partial is just modularized/reusable views. Just like you can use code inside an instance method and inside a class method, because they're just code, so can you use the same HAML code in a partial and in a "regular" view.
There are a bunch of ways to do this. I would not use partials, I would do:
%li{:class => #active_page=="careers" ? "active_page" : ""}
%a{:href => "../pages/careers"} Careers
Assuming #active_page has been created by your controller.