How to set data-attribute between image's src and alt attributes? - simple-html-dom

Order:
$img->src = 'someimage.webp';
$img->alt = null;
$img->{'data-ext'} = 'png';
$img->alt = 'somealt';
Result:
<img src="someimage.webp" alt="somealt" data-ext="png">
I'm trying to get this:
<img src="someimage.webp" data-ext="png" alt="somealt">
UPD
I found ugly solution, but this returns valid html
$img->src = 'someimage.webp" data-ext="png';
$img->alt = 'somealt';

If you want the data-attribute to be between src and alt and setting the alt to null in between, one option could be to getAllAttributes() and use krsort to sort the array keys in reverse order.
For example
$img->src = 'someimage.webp';
$img->alt = null;
$img->{'data-ext'} = 'png';
$img->alt = 'somealt';
$attrs = $img->getAllAttributes();
krsort($attrs);
$img->attr = $attrs;
echo $img->outertext();
Output
<img src="someimage.webp" data-ext="png" alt="somealt">

Related

Get second attribute with Beautiful Soup

I've got this html and a series of images to get with this structure:
<portrait a>
<img class = "image" data = "random stuff" src = "image_link">
<portrait b>
<img class = "image" data = "random stuff" src = "image_link">
I want to get the image_link. I've tryed this but it didn't work. I don't understand how to get the second attribute with get().
i = d.find_all("img", class_ = "image")
for item in i:
img = item.get("src")
print(img)
Thanks
Try like this:
from bs4 import BeautifulSoup
htmlcontent = """
<portrait a>
<img class = "image" data = "random stuff" src = "image_link1">
<portrait b>
<img class = "image" data = "random stuff" src = "image_link2">
"""
soup = BeautifulSoup(htmlcontent,"lxml")
for item in soup.find_all("img",class_="image"):
print(item.get("src"))
Output:
image_link1
image_link2

TYPO3 show content from subpages inlcuding css classes

With the following typoscript I get all content from the subpages on one page:
lib.allPid = COA
lib.allPid {
10 = HMENU
10 {
special = directory
special.value = 2
1 = TMENU
1 {
expAll = 1
NO.doNotShowLink = 1
NO.allStdWrap.field = uid
NO.allStdWrap.wrap = |,
}
2 < .1
}
}
lib.allContent = CONTENT
lib.allContent {
table = tt_content
select {
pidInList.cObject < lib.allPid
leftjoin = pages ON (tt_content.pid = pages.uid)
where = tt_content.colPos = 0
orderBy = pages.sorting ASC
}
}
But its not copying the tt_content wrap defined by the layout selectbox in the content element:
tt_content.stdWrap.innerWrap.cObject.default.20.40 = CASE
tt_content.stdWrap.innerWrap.cObject.default.20.40 {
key.field = layout
1 = TEXT
1.value = tag-1
2 = TEXT
2.value = tag-2
3 = TEXT
3.value = tag-3
4 = TEXT
4.value = tag-4
5 = TEXT
5.value = tag-5
6 = TEXT
6.value = tag-6
7 = TEXT
7.value = tag-7
}
I tried to add the wrap to the lib.allContent element like this, but it didn't work:
lib.allContent.stdWrap.innerWrap.cObject.default.20.40 = CASE
lib.allContent.stdWrap.innerWrap.cObject.default.20.40 {
key.field = layout
1 = TEXT
1.value = tag-1
2 = TEXT
2.value = tag-2
3 = TEXT
3.value = tag-3
4 = TEXT
4.value = tag-4
5 = TEXT
5.value = tag-5
6 = TEXT
6.value = tag-6
7 = TEXT
7.value = tag-7
}
Does anybody know how to do this? Thanks in advance!
EDIT:
I found a solution (or better: workaround) without typoscript. I insert the contents from the subpages with "New content element - Special Elements - Insert Record" manually one by one. Then, everything is copied. This solutions requires a little more user input but fits perfectly to my needs.
give a try to vhs ViewHelper it'll give you exact output what you want I mean default wrap and at all.
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<v:page.menu pageUid="2" includeSpacers="0" resolveExclude="1">
<f:for each="{menu}" as="contentList" iteration="Iteration">
<div id="uid{contentList.uid}" class="inner-page-content-of-pageUid-2">
<v:content.render column="0" pageUid="{contentList.uid}" />
</div>
</f:for>
</v:page.menu>
something more about vhs ViewHelper

Align Image inside cell to the right doesn't work

I need to align on the headers an image to the right. This is my code:
Section section = document.AddSection();
table = section.Headers.Primary.AddTable();
var column = table.AddColumn("5cm");
column.Format.Alignment = ParagraphAlignment.Left;
column = table.AddColumn("8cm");
column.Format.Alignment = ParagraphAlignment.Left;
column = table.AddColumn("4cm");
column.Format.Alignment = ParagraphAlignment.Right;
eRow.Cells[0].AddParagraph("Some text");
eRow.Cells[1].AddParagraph("Some text");
eRow.Cells[2].Format.Alignment = ParagraphAlignment.Right;
image = eRow.Cells[2].Elements.AddImage(imagePath);
image.LockAspectRatio = false;
image.Width = Unit.FromInch(0.16);
image.Height = Unit.FromInch(0.09);
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Right;
image.WrapFormat.Style = WrapStyle.Through;
But it's always to the left, any help please?
I know it is a bit late
But you have to wrap your image in a paragraph.
http://forum.pdfsharp.net/viewtopic.php?f=2&t=158
Something like (I use parts of your code)
Section section = document.AddSection();
table = section.Headers.Primary.AddTable();
var column = table.AddColumn("5cm");
//I assume eRow is just a row added to your table
var eRow = table.AddRow();
var paragraph = eRow.Cells[0].AddParagraph();
//set the alignment on the paragraph object
paragraph.Format.Alignment = ParagraphAlignment.Right;
paragraph.AddImage(imagePath);
I had the same problem at it worked with the code/link from above.
The lines
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Right;
image.WrapFormat.Style = WrapStyle.Through;
logically take the image out of the cell. This creates an image that can appear anywhere on the page, not just inside the cell.
Maybe it works if you simply remove those five lines. Maybe it works if you add a Paragraph to the Cell and add the Image to the cell.
If you would have supplied an MCVE I would have tried if my suggestions work. But you only show a code snippet.
The line image.LockAspectRatio = false; is superfluous, but does no harm.
It will work if you do like that:
row.Cells[1].AddParagraph().AddImage(fileName);
row.Cells[1].Format.Alignment = ParagraphAlignment.Right;

How to set %Dictionary.StorageSQLMapDataDefinition.RetrievalCode?

How can I do this:
<Data name="hyperlink">
<RetrievalCode>
<![CDATA[set res=""
set colId=""
for
{
set colId = $order( ^ohtest("mltab","main","Dta",{L4},colId) )
quit:(colId = "")
set indexTab = $g(^ohtest("mltab","main","Dta",{L4},colId,"Index"))
if indexTab'="" {
set res = res_"<hyperlinkIndexTab><colId>"_colId_"</colId><iTab>"_indexTab_"</iTab></hyperlinkIndexTab>"
}
}
s {hyperlink}=res]]></RetrievalCode>
</Data>
programatically?
I have:
set global = "^ohtest"
set iTab="main"
//hyperlink
set storData = ##class(%Dictionary.StorageSQLMapDataDefinition).%New()
set storData.Name = "hyperlink"
set storData.RetrievalCode = "<![CDATA[set res="""" set colId="""" for{set colId = $order( "_global_"(""mltab"","_iTab_",""Dta"",{L4},colId) ) quit:(colId = """") set indexTab = $g("_global_"(""mltab"","_iTab_",""Dta"",{L4},colId,""Index"")) if indexTab'="""" {set res = res_""<hyperlinkIndexTab><colId>""_colId_""</colId><iTab>""_indexTab_""</iTab></hyperlinkIndexTab>""}} s {hyperlink}=res]]>"
do storMap.Data.Insert(storData)
But it doesn't work. How to let generate code provided above?
your first problem is, putting CDATA declaration in code. Caché will add it without you, and then you put iTab without quotes.
set global = "^ohtest"
set iTab="main"
set data=##class(%Dictionary.StorageSQLMapDataDefinition).%New()
set data.Name="hyperlink"
set code=""
set code=code_"set res="""""_$c(13,10)
set code=code_"set colId="""""_$c(13,10)
set code=code_"for"_$c(13,10)
set code=code_"{"_$c(13,10)
set code=code_" set colId = $order( "_global_"(""mltab"","""_iTab_""",""Dta"",{L4},colId) )"_$c(13,10)
set code=code_" quit:(colId = """")"_$c(13,10)
set code=code_" set indexTab = $g("_global_"(""mltab"","""_iTab_""",""Dta"",{L4},colId,""Index""))"_$c(13,10)
set code=code_" if indexTab'="""" {"_$c(13,10)
set code=code_" set res = res_""<hyperlinkIndexTab><colId>""_colId_""</colId><iTab>""_indexTab_""</iTab></hyperlinkIndexTab>"""_$c(13,10)
set code=code_" }"_$c(13,10)
set code=code_"}"_$c(13,10)
set code=code_"s {hyperlink}=res"_$c(13,10)
set data.RetrievalCode=code
do storMap.Data.Insert(data)

Action Script 3.0 : How to extract two value from string.?

HI
I have a URL
var str:String = "conn=rtmp://server.com/service/&fileId=myfile.flv"
or
var str:String = "fileId=myfile.flv&conn=rtmp://server.com/service/"
The str might be like this, But i need to get the value of "conn" and "fileId" from the string.
how can i write a function for that.
I'm guessing that you're having trouble with the second '=' in the string. Fortunatly, ActionScript's String.Split method supports splitting on strings, so the following code should work:
var str:String = "conn=rtmp://server.com/service/&fileId=myfile.flv";
var conn:String = (str + "&").Split("conn=")[1].Split("&")[0];
and
var str:String = "fileId=myfile.flv&conn=rtmp://server.com/service/";
var fileId:String = (str + "&").Split("fileId=")[1].Split("&")[0];
Note: I'm appending a & to the string, in case the string didn't contain any url parameters beyond the one we're looking for.
var str:String = "fileId=myfile.flv&conn=rtmp://server.com/service/"
var fa:Array = str.split("&");
for(var i:uint=0;i<fa.length;i++)
fa[i] = fa[i].split('=');
That's how the "fa" variable be in the end:
fa =
[
["fileId","myfile.flv"],
["conn","rtmp://server.com/service/"]
]
var url:String = "fileId=myfile.flv&conn=rtmp://server.com/service/";
var strArray:Array = url.split(/=/);
trace(strArray[0]) //Just to test
returns an array, with the word 'conn or fileid' in index 0 - 2 (anything even), alternatives of 1, 3 is the information within.
Or was it something else you needed?

Resources