Yii URL Rules Rewrite - url

I have the folowing URL rule in main.php under urlManager, rules:
the-urly-bird => blog/content/index,
This page (http://www.accesstheflock.io/the-urly-bird) has 10 pages of content. I would like each page to have it's own URL like: http://www.accesstheflock.io/the-urly-bird/page/2.
The path for each page is: ?r=blog/content/index&Content_page=2
Please provide URL rules for main.php to make this work. This is very much appreciated. Thank you.

I was able to write working URL rules and add a jQuery on click event handler to redirect to the right url for the pagination.
main.php
'the-urly-bird/page/<page:\d+>'=>'blog/content/index',
'the-urly-bird' => 'blog/content/index',
view
$('li.page a').on('click', function() { //Redirects
window.location.href = $(this).attr('href');
return false;
}); –

Related

Passing a URL Parameter via a button link

Very simply, I'm looking for a way to grab the value of a URL parameter and pass this to a target URL inside a button.
Ex:
Page URL: https://example-domain.com/page-1?parameter=value1
In this page, there is a button with the link URL: https://example-domain.com/page-2
I'm looking for a way to have this link to be dynamically updated to https://example-domain.com/page-2?parameter=value1
Is there a way that I can handle without a deep understanding of any coding language for my Wordpress website?
Thanks in advance
The solution I found is:
LINK_TEXT_HERE
<script type="text/javascript">
jQuery(function() {
var el = document.getElementById('ELEMENT_ID_HERE');
el.href = el.href + window.location.search;
});
</script>

Rails 5: Google Tag Manager will not fire

I am using Google Tag Manager and it just stopped working on the landing page that client's are redirected to after filling out a form. It works if you refresh the page, but doesn't work on redirects.
I know this smells like turbolinks, so I've modified the javascript function like so many articles have recommended:
<script>
document.addEventListener('turbolinks:load', function(event) {
console.log(event, dataLayer)
var url = event.data.url;
dataLayer.push({
'event':'pageView',
'virtualUrl': url
});
});
(function(w,d,s,l,i){
console.log("getting it")
w[l]=w[l]||[];w[l].push({
'gtm.start': new Date().getTime(),event:'gtm.js'
});
var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})
(window,document,'script','dataLayer','GTM-######');
</script>
In my console, I see the console.log(event, dataLayer) but there is no request to: https://www.googletagmanager.com/gtm.js?id=GTM-######
When I refresh the page, I see the same things logged to my console, but there IS a request to https://www.googletagmanager.com/gtm.js?id=GTM-######.
Does anyone know how to make this request fire or understand what might be going wrong?

Prepend a word to all ajax urls by some configuration change in rails app

I have a rails app in which I have used ajax calls with some url. I want to append project name to the ajax urls. One way is to edit all urls. Is there any other simpler way to do the same?
To prepend a word (let it be project_name) to all ajax calls in application write the following code in a js file:
$.ajaxSetup({
beforeSend: function(data, settings) {
var url = "/project_name"+ settings.url;
settings.url = url;
}
});

Counting clicks to external links with rails

I have Entry model with url field, which contains link to external site.
In view I list these links, and now I'd like to start counting when someone clicks it, and keep this info in database. What's the best way of doing it?
You can easily use google analytics to track outbound links: http://support.google.com/analytics/bin/answer.py?hl=en&answer=1136920
If that is not an option you will need to add some javascript to your links make an ajax request to the server to increment the count before transferring the user to the new url. Something similar to this jquery code:
$('a').click(function(){
var stored_ulr = $(this).attr('href');
$.ajax({
url: #your server url to increment count,
data: #data you need to send,
success: function() { window.location = stored_url; },
});
return false;
});
The above code is just a general outline. You will have to fill in the blanks and make it work for your needs.

Broken relative Url in jQuery getJSON Ajax Method

The Url for my development environment is:
http://localhost/mysite/blah...
I am using jQuery & getJSON to perform some ajax actions on my site, which work fine all the time I specify the url as:
/mysite/controller/action
..but this is not ideal as I don't want to hardcode my development url into my seperate jQuery include files.
When the site goes live, it'll be fine to have controller/action or /controller/action as the url as that will resolve ok, but for the development site, it's no go.
I've tried:
controller/action
..but this returns a 404, which suprised me as I thought the lack of / at the front of the url would prevent from looking at the website root.
There must be a neat solution to this?
I would do this by inserting a global constant in my HTML header:
<script type="text/javascript">
var BASE_URL = '/mysite/';
</script>
That would be inserted from your server so it can be dynamically changed.
Later in your script, you'll be able to make AJAX requests with (jQuery style here):
$.ajax( BASE_URL + '/controller/action', ...);
If you're in
/mysite/controller/action
then the correct relative path to
/mysite/some_other_controller/some_other_action
is
../../some_other_controller/some_other/action
You can use this code to get the current path of the .js script and use it for calculate your relative path.
var url;
$("script").each(function () {
if ($(this).attr("src").indexOf("[YOUR_SCRIPT_NAME.JS]") > 0) {
url = $(this).attr("src");
url = url.substr(0, url.lastIndexOf("/"));
return false;
}
});
var final_url = url + "/your_target_script.js"
Replace YOUR_SCRIPT_NAME with the unique name of your script.

Resources