ExpressionEngine add class to wrap parameter - expressionengine

I have entries that contain an image as a channel entry field. I am using the following syntax in my template to generate an alt tag w/ data. The problem I have is that I haven't found a way to add a class attribute to the generated img tag.
{info-image wrap="image" class="img-responsive"}
outputs
<img src="http://secretproject.dev/images/uploads/general/dedication2.jpg" alt="dedication2">
where the alt data is the image title.
If I take another approach and write
<img class="img-responsive" src="{info-image}" alt="{title}">
then the title comes from the entry itself and not the file title.
In summary, I need both class and alt attributes but seem to be stuck with one or the other. Is there a way to achieve this in either syntax? Is there another approach? Thanks

You can use the variable pair syntax as described in the documentation.
{info-image}
<img src="{url}" alt="{title}" class="img-responsive">
{/info-image}

Related

Extract multiple image links from a single div tag that has no class name

Hi I have this HTML code from a website: I want to be able to extract multiple images, I have cases where there is 3-4 images. How would I go about doing that?
<div style="float: right;"><u>Chakra required:</u>
<img src="https://naruto-arena.net/images/energy/energy_2.gif">
<img src="https://naruto-arena.net/images/energy/energy_4.gif">
</div>
My code:
chakras1 = soup.find_all("div")[42].img['src']
print(chakras1)
Result:
https://naruto-arena.net/images/energy/energy_2.gif
I only get the FIRST image but now the second one.
To extract multiple images from within a tag, I personally stick to using for loops. So what I mean is once you find the div tag that you want to look within and say you call that chakras1, I would write the following:
for img in chakras1.find_all("img"):
print(img)
For me the steps kind of go as follows:
find the specific tags you are looking for (img src)
see what tag those tags are within (
navigate through the HTML to that tag (using beautiful soup's .find or .find_all functions depending on what you want to use)
once you have navigated to the tag search within that tag for the tags you're really looking for.
One quick note, with this method, if you are looking through multiple div tags, you're also going to need to loop through those as well.
I hope this makes sense!

Cannot identify the object in Selenium

I cannot identify the object of the icon showed in the attached screen shot. I have shown the HTML code as well.
The ID's are getting changed dynamically.
Can anyone guide on how to identity this kind of objects in Selenium?
If the ID is always changed, I recommend using CssSelector instead.
For instance,
<div id="running_number_12345" class="icon something">...</div>
You can use locator
driver.FindElement(By.CssSelector("div[class*='icon something']"));
If your icon doesn't have any specific css pattern, I recommend adding something in class attribute. If not, you have to use complex CssSelector to find it.
Try this
driver.findElement(By.cssSelector(".icon something"));

Selecting parent elements with WebdriverJS

I'm trying to create some scripts which require moving through a lot of on-the-fly HTML with random IDs. They require getting the parents of an element - but I'm not sure how to implement this in WebdriverJS.
If I access the element I want via a console, I can do the following to get it;
document.querySelector('span[email="noreply#example.com"]').parentNode.parentNode
Is there a way to do this in WDJS? I've looked and can't see anything obvious - it's specifically the parent stuff I'm having issue with. I saw that a possible solution may be xPath however I'm unsure of syntax having never used it before.
Thanks in advance!
I don't know the syntax of WebDriverJS. But the XPath is as below, you need a way to fit it in somewhere.
This is based on your CSS Selector, so please show HTML if needed.
.//span[#email='noreply#example.com']/../..
For example, if you have HTML like this
<div>
<div>
<span email="noreply#example.com">Contact me</span>
</div>
</div>
You can avoid using .. to go up.
.//div[./div/span[#email='noreply#example.com']]
If you have more levels to look up, another handy method would be using ancestor from XPath Axes.
Also, as #sircapsalot brought up, CSS selectors spec doesn't support parent selecting, so XPath is the only way to go, unless you inject JS.

URL title to Entry ID on Channel Entries tag

I'm trying to use the "URL title to Entry ID" plugin to feed the entry_id parameter into a Channel Entries tag, but can't figure out a way to get the ID information inserted early enough in the template parsing order.
This doesn't work - it picks up no entry ID, and so displays all entries:
{exp:channel:entries entry_id="{exp:url_title_to_entry_id parse="inward" url_title="{last_segment}"}" dynamic="no"}
{title}
{/exp:channel:entries}
Any suggestions would be much appreciated.
You can't have a function tag as a parameter to another function tag.
So either you have to pass the {exp:url_title_to_entry_id} result as an embed variable to another template that holds the channel:entries tag, or you have to use tag pairs so that one function tag, wraps the other and uses variables.
url_title_to_entry_id doesn't allow for tag pair, so either use the embed technique, or use another add-on.
BUT, you don't need the add-on at all...
{exp:channel:entries url_title="{last_segment}" dynamic="no"}
{title}
{/exp:channel:entries}
reference.
I'd also suggest added required_entry="yes" and limit="1" and then add {if no_results}...{/if} conditional inside. This will prevent it outputting all entries if it can't find a match.

Using resource files in SharePoint MasterPages

I haven't been able to figure out how to use strings from resource files (resx) in SharePoint master pages.
I know how to use it with server controls, but can I somehow extract a value and use it in generalt html. I.e. in an alt attribute on a img tag?
<img src="photo.jpg" alt="my_resource_entry_here" />
Here are 2 very good blog posts that describe how to use resources:
http://tomblog.insomniacminds.com/2008/02/25/sharepoint-internals-resources/
http://www.mikhaildikov.com/2007/03/sharepoint-resources-types-use-and_2163.html
The easiest way would be to add a runat="server" attribute to your alt tag. That will solve your problem and you can use the "normal" way of getting resources.
Othwerwise use this syntax to get value from the resx files places in App_Global resources:
<img src="photo.jpg"
alt='<%=this.GetGlobalResourceObject("Global", "Mystring").ToString()%>'
I assume you have a class with a method that lets you get the resource string by the key, e.g. MyResources.GetString(key). In that case you can use something like this:
<img src="photo.jpg" alt='<%=MyResources.GetString("my_resource_key_here")%>' />

Resources