Magento Template Hints won't turn off on only one page. Debugging - magento

I am having a strange problem whereby my template path hints will not deactivate on a single only.
Previously to this I was having a strange error where the contact form on the page would submit, but would display it's success message on the product page.
This issue seemed to be resolved after clearing the cache (we use APC cache, which was also cleared). The thing was I submitted the contact form while the template hint where still on, and since then have been unable to turn them off for that page only.
I have tried the usual procedures of going up and down stairs with the cache, and also deleting the contents of the cache folder from the terminal.
Has anyone any suggestions where I would even begin to debug this?
Thanks

I'd start by dropping into the base template class
#File: app/code/core/Mage/Core/Block/Template.php
and figuring out why the getShowTemplateHints method is returning true on that page
#File: app/code/core/Mage/Core/Block/Template.php
public function getShowTemplateHints()
{
if (is_null(self::$_showTemplateHints)) {
self::$_showTemplateHints = Mage::getStoreConfig(self::XML_PATH_DEBUG_TEMPLATE_HINTS)
&& Mage::helper('core')->isDevAllowed();
self::$_showTemplateHintsBlocks = Mage::getStoreConfig(self::XML_PATH_DEBUG_TEMPLATE_HINTS_BLOCKS)
&& Mage::helper('core')->isDevAllowed();
}
return self::$_showTemplateHints;
}
Or, of it's returning false, why does the base template class still reach the rendering point.
#File: app/code/core/Mage/Core/Block/Template.php
if ($this->getShowTemplateHints()) {
echo <<<HTML
<div style="position:relative; border:1px dotted red; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;">
<div style="position:absolute; left:0; top:0; padding:2px 5px; background:red; color:white; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'"
onmouseout="this.style.zIndex='998'" title="{$fileName}">{$fileName}</div>
HTML;
if (self::$_showTemplateHintsBlocks) {
$thisClass = get_class($this);
echo <<<HTML
<div style="position:absolute; right:0; top:0; padding:2px 5px; background:red; color:blue; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'" onmouseout="this.style.zIndex='998'"
title="{$thisClass}">{$thisClass}</div>
HTML;
}
}

Refreshing the cache solved this problem for me.

After checking each store view for template hints and clearing server and local cache I cleared the cache again and then restarted apache.

Related

Skeleton page with v-cloak: how to target loading div with css ? Vue

I'm using Webpack/Laravel and injecting vuejs on id #app in my page so to have skeleton loading page I want to have this markup
//client side, will show after ~0.2 seconds
<div id="app" v-cloak>
<hello-world>
</div
//server side, show for ~0.2 s then disappear
<div id="app__loading" v-cloak>
<div class="skeleton">
<span class="skeleton_ribs"></span>
</div>
</div>
I managed to display loading gif in background as pseudo element when v-cloak and everything inside from #app__loading is removed, but if I add normal elements in markup they appear at the bottom of the page after #app loads
[v-cloak] > * { display:none }
[v-cloak] + #app__loading::before {
content: url('https://i.pinimg.com/originals/65/ba/48/65ba488626025cff82f091336fbf94bb.gif');
display: flex;
justify-content: center;
align-items: center;
}
But I would like something like this to work with markup inside #app__loading, but it doesn't work
[v-cloak] > * { display:none }
#app-loader{
display: block;
}
[v-cloak] #app::finish-loading{
[v-cloak] #app-loader{
display: none!important;
}
}
You seem to be expecting the content your initial element to be found in the template of app root element. When using $mount() function, Vue completely replaces the target element with the template of the mounted element.
This replacement is somewhat masked by the fact that, out of the box, the index.html contains a <div id="app"> which gets replaced by the <div id="app">...</div> in your App.vue template.
But they're actually not related (and not the same element). If you changed the id of the one in index.html you'd need to change the target el in main.(js|ts). And obviously, you could change the id of the one in App.vue as well.
Now, to solve your issue, you could simply place v-cloak on the div in your App.vue. From what you've shown so far, that should make it work as expected.
For more complex use cases (i.e: if you wanted to trigger a particular event bound to the initial element) the way to go would be to wrap the initial placeholder in a parent, bind to the parent and, later on, in Vue, target the parent with this.$el.closest('.some-class') or with this.$el.parentElement() to access the binding.
If you still can't get the expected result, please create a mcve (you could use codesanbox.io) and describe in detail what is the expected behavior.
To make your headache smaller till you find proper vue solution, you can grab loader by id and when Vue instance mounts - give display none
export default {
mounted() {
document.querySelector('#app__loading').style.display = 'none';
},
}

How to specify background image with Thymeleaf?

I'm learning spring boot with thymeleaf. I've stored user object's profile image in the file system and only the URL of the image is part of the User object persisted in the database.
I've added the name and dpurl into the model, in order to access it from the template.
#GetMapping("/profile")
public String profileController(#AuthenticationPrincipal User activeUser, Model model) {
model.addAttribute("name", activeUser.getName());
model.addAttribute("dpurl", activeUser.getDpURL());
return "profile";
}
I'm able to access name from template using th:text="${name}"
However, I'm not able to specify background image using thymeleaf like this
<div id="dp-container" th:style="'background-image: url(' + #̣{dpurl} + ');'" >
this is resulting in error Could not parse as expression: "'background-image: url(' + #̣{dpurl} + ');'"
Update
Changed it like this
<div id="dp-container" th:style="'background-image:url(' + #{dpurl} + ');'">
Now I'm not getting any error but background image still not being displayed.How to specify background-image using Thymeleaf?
It probably needs to look like this:
<div id="dp-container" th:style="'background-image:url(' + ${dpurl} + ');'">
But it depends on what dpurl contains. Do you really need to use #{...}? Then you should use #{${dpurl}}.
To debug this, you should be looking at the source. it will reveal what your expressions are resolving too.
I got this to work:
<td th:style="'background: url(/images/aws2.png)'" class="fluid hero-image" >
Well, if you've got something more complex like needing to pass a variable into the url, you can try this:
<div id="profile_image" th:style="'background-image: url('+ #{'/view-profile-pic/' + ${result.profile_pic}} +');'"></div>
And in css, the image was displayed correctly with:
#profile_image {
margin: auto;
height: 200px;
width: 200px;
box-sizing: border-box;
border-radius: 100px;
background-size: cover;
}
I stumbled upon this solution when I wanted to display profile pictures received from search results.
You could try this too if none of the others work. Upload the image to some online store like a file sharing service or google drive and provide the link to the image as the url for your background-image property.
<div id="dp-container" style="background-image: url(Link to the image);" >

HTA Self-Modifying Code?

I'd like to try to make an HTA that holds some data between sessions. The file might move from one computer to another, so I don't want to depend on cookies, and it won't have some remote server to save data to, so my hope is to find a way to use scripting like vbscript to write the save data back to the HTA itself, so that the next time the application runs, it already has the latest information.
What I'd likely do is dedicate a run of lines in the code as a list of variable declarations that will be used to initialize the application. There would be some kind of "save" button in the application that will read the current state of those variables and edit the hta file's source code, specifically on those lines and replace the values with whatever the current values are.
Since an HTA file is essentially just a text file with a different extension, I would assume there's a way to have the HTA edit itself like any other file...but I don't actually know how to do it, or how to isolate the lines of code where the variables will reside and edit them without having to load the entire file into memory and save the entire thing each time I want to save something... I'd like to keep things completely self-contained, so I don't want to depend on external files like an XML or CSV to store settings between sessions, so I'd like to be able to embed the data into the HTA.
You can indeed modify an HTA file while it's running because it's interpreted code. Same way you can modify an HTML file while you're viewing in your browser.
However, I would not do it that way unless there is some compelling reason you must keep everything in 1 file. If there is a problem writing to the HTA, you will end up with a blank file and lose everything. Therefore, I recommend using a plain text file to store your data and include that with your HTA.
MyApp.hta:
<!doctype html>
<HTA:APPLICATION
APPLICATIONNAME="MyApp"
SINGLEINSTANCE="yes"
CONTEXTMENU="no"
ICON=""
ID="HTA"
INNERBORDER="no"
NAVIGABLE="no"
SCROLL="yes"
SHOWINTASKBAR="yes"
VERSION="0.0.1"
/>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<title>MyApp</title>
<style type="text/css">
body { font-family: Calibri, Arial; font-size: 20px; }
label { font-weight: bold; }
.settings__container { position: relative; height: 200px; border: 2px dashed #ccc; overflow: hidden; padding-right: 2px; }
#settings { width: 100%; height: 100%; border: 0; }
</style>
</head>
<body>
<label>Settings:</label>
<div class="settings__container">
<textarea id="settings"></textarea>
</div>
<button id="save-settings__button">Save Now</button>
<script type="text/javascript">
(function() {
var settingsElement = document.getElementById('settings'),
settingsFile = "MyApp.settings.txt",
io = new ActiveXObject('Scripting.FileSystemObject');
function loadSettings() {
try {
var file = io.OpenTextFile(settingsFile, 1),
data = file.ReadAll();
file.Close();
settingsElement.value = data;
} catch(e) {
// Failed to load settings; settings file may not exist yet.
}
}
function saveSettings(data) {
var file = io.OpenTextFile(settingsFile, 2, true);
file.Write(data);
file.Close();
}
// Assuming IE9+
document.getElementById('save-settings__button').addEventListener('click', function(e) {
saveSettings(settingsElement.value);
});
// Load the settings file
addEventListener('load', function(e) {
loadSettings();
});
// Save the settings on exit
addEventListener('unload', function(e) {
saveSettings(settingsElement.value);
});
})();
</script>
</body>
</html>
Have a look at the FileSystemObject. If you're using vbscript, you would need to
Open the HTA file with OpenTextFile
Read the file
Modify the lines you want changed
Write the new contents to the file with CreateTextFile (Overwrite set to True)
For using Javascript the procedure is the same, the methods are slightly different.

how to create function for load menu in codeigniter

i'm litte confuse about this, so i wanna make one function which called menu_function.
for what? so all file php in view, will load this menu_function
this menu_function will load menu option in each php file in view, so it will load different menu option in different php file in view
what i'm think is like this
public function menu_function()
{
$dataV["menu"] = "<a href='profit' style='color:blue; font-size: 14px; font-weight: bold;'>Profit PT</a>";
$dataV["menu1"] = "<a href='profit/member' style='color:blue; font-size: 14px; font-weight: bold;'>Profit Member</a>";
$this->load->view("test", $dataV);
}
i think is bad having html tag in controller or i already read this, according that is efficient i make another php in view just for menu option and load in another view?
why i want to make this? so in future if i wanna add another menu option or remove 1 or more menu option just change in 1 file, not having open all view and remove menu option 1 by 1.
maybe another suggest? thanks
What I would do is to create a templates folder inside the views directory, and put there view files that you may require from several controllers.
/application/views/templates
Let's name that file header.php and it would look like this
<a href='<?php echo site_url('profit'); ?>' style='color:blue; font-size: 14px; font-weight: bold;'>Profit PT</a>
<a href='<?php echo site_url('profit/member); ?>' style='color:blue; font-size: 14px; font-weight: bold;'>Profit Member</a>
Then, you could include this template in every controller you would want
$this->load->view('templates/header');
Also, for future reference, if you want a function to be available in different controllers you can:
Extend the CI_Controller core class.
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
}
/* define here all the functions you want */
}
Then you would create your controllers extending MY_Controller instead of CI_Controller whenever you would want to call the functions.
Use helpers, libraries and drivers.

Scraping a site that requires login username and password on two separate pages

I'm trying to scrape information from my companies Intranet so that I can display information on our office wall board via dashing dashboard. I'm trying to work with the provided information from:This Site.The problem that I'm having other than being a noob is that in order to gain access to the information I want to scrape, I need to login to our Intranet providing my username on one page then submitting to another so that I can provide my password. Once I'm logged in, I can then link and scrape my data.
Here is some source code from my login username page:
<form action='loginauthpwd.asp?PassedURL=' method='post' style='margin: 0px;'><table border='0' cellspacing='1' width='999' height='350'><tr><td width='100'> </td><td valign='center' width='100'><table style='width: 350px; background-color: #EEEEEE; border: 1px solid gray;'><tr><td class='fontBlack' style='padding: 10px; vertical-align: top;'><span style='font-weight: bold;'>Username:</span><br><input type='text' class='normal' autocomplete='off' id='LoginUser' name='LoginUser' style='border: 1px solid gray; height: 16px; font-family: arial; font-size: 11; width: 180px;' maxlength='30'><input class='normal_button' type='button' value='Go' style='border: 1px solid gray; font-weight: bold; width: 80px; margin-left: 10px;' onclick="var username=document.getElementById('LoginUser').value; if (username.length > 2) { submit(); } else { alert('Enter your Username.'); }"></form>
Here is some source from my login password page:
<form action='loginauthprocess.asp?UserName=******&Page=&PassedURL=' target='_top' method='post' onsubmit='checkMyBrowser();' style='margin: 0px;'><table border='0' cellspacing='1' width='999' height='350'><tr><td width='100'> </td><td valign='center' width='100'><table style='width: 350px; background-color: #EEEEEE; border: 1px solid gray;'><tr><td class='fontBlack' style='padding: 10px; vertical-align: top;'><span style='font-weight: bold;'>Password:</span><br><input class='normal' type='password' autocomplete='off' id='LoginPassword' name='LoginPassword' style='border: 1px solid gray; height: 16px; font-family: arial; font-size: 11; width: 180px;' maxlength='30'><input class='normal_button' type='submit' value='Log In' style='border: 1px solid gray; font-weight: bold; width: 80px; margin-left: 10px;' onclick="var password=document.getElementById('LoginPassword').value; if (password.length > 2) { submit(); } else { alert('Enter your Password.'); }"></form>
Using said resource's example this is what I think should work but doesn't seem to be:
require 'mechanize'
#agent = Mechanize.new
#agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
##Login Page:
page = #agent.get 'http://www.website_here.com/intranet/login.asp'
##Username Page:
form = page.forms[0]
form['USER NAME HERE'] = LoginUser
##Submit User:
page = form.submit
##Password Page:
form = page.forms[0]
form['USER PASSWORD HERE'] = LoginPassword
##Submit Password:
page = form.submit
When I test my code I get the following output:
test.rb:10:in `': uninitialized constant LoginUser (NameError)
Can anyone point out what I'm doing wrong?
Thanks
EDIT 3/27/15:
Using #seoyoochan resource I tried to form my code like this:
require 'rubygems'
require 'mechanize'
login_page = agent.get "http://www.website_here.com/intranet/loginauthusr.asp?Page="
login_form = login_page.form_with(action: '/sessions')
user_field = login_form.field_with(name: "session[user]")
user.value = 'My User Name'
login_form.submit
When I try to run my code I'm now getting this output:
test.rb:4:in <main>': undefined local variable or methodagent' for main:Object (NameError)
I'm needing an example on how to assign the right names/classes that my provided form will work with.
EDIT 4/4/15:
Okay, Now using #tylermauthe example I'm trying to test the following code:
require 'mechanize'
require 'io/console'
agent = Mechanize.new
page = agent.get('http://www.website_here.com/intranet/loginauthusr.asp?Page=')
form = page.forms.find{|form| form.action.include?("loginauthpwd.asp?PassedURL=")}
puts "Login:"
form.login = gets.chomp
page = agent.submit(form)
pp page
Now my thoughts are that this code should allow me to enter and submit my username bringing me to my next page that would ask for my password. BUT, when I try to run it and enter my username, I get the following output:
/var/lib/gems/1.9.1/gems/mechanize-2.7.3/lib/mechanize/form.rb:217:in method_missing': undefined methodloginUser=' for # (NoMethodError)
from scraper.rb:10:in `'
What am I missing or have entered wrong? Please refer to my first edit to see how my form is coded. Also to be clear I did not code the forms this way. I'm only trying to learn how to code and scrape data needed to display on my Dashing Dashboard project.
I was able to get logged in with the following example. Thanks to everyone that helped me with all the resources and examples to learn from!
require 'nokogiri'
require 'mechanize'
agent = Mechanize.new
# Below opens URL requesting username and finds first field and fills in form then submits page.
login = agent.get('http://www.website_here.com')
login_form = login.forms.first
username_field = login_form.field_with(:name => "user_session[username]")
username_field = "YOUR USERNAME HERE"
page = agent.submit login_form
# Below opens URL requesting password and finds first field and fills in form then submits page.
login = agent.get('http://www.website_here.com')
login_form = login.forms.first
password_field = login_form.field_with(:name => "user_session[password]")
password_field = "YOUR PASSWORD HERE"
page = agent.submit login_form
# Below will print page showing information confirming that you have logged in.
pp page
I found the following example from user:Senthess HERE. I'm still not 100% on what all the individual code is doing so if anyone would like to take the time and break it down, please do so. This will help myself and others to better understand.
Thanks!
I just looked up about Mechanize gem and found a relevant solution.
You must set a proper 'name' on input fields. Otherwise you can't accept values from them.
Follow this article.
http://crabonature.pl/posts/23-automation-with-mechanize-and-ruby
Not sure if you found these, but Mechanize has fairly excellent docs: http://docs.seattlerb.org/mechanize/GUIDE_rdoc.html
From these, I played around in the irb REPL to create this simple scraper that logs into
GitHub:
https://gist.github.com/tylermauthe/781f68add24819e207c4

Resources