I was looking through the atom documentation at writing snippets:
Using atom snippets
However, the documentation is too simple for the problem I'm facing. I want to write a snippet that will automatically create a comment that will contain a class name of the HTML element. Let's see an example:
<div class="first-class another-class">
...
</div><!-- first-class another-class -->
I want to have a snippet that will automatically create the comment containing "first-class another-class" when I type, for instance, "comm" after the closing tag of the div and hit TAB. Is this even possible with snippets?
Doesn't your workflow allow you to create the comment together with the preceding tag? In that case, you could use something like this:
'.text.html':
'Snippet Name':
'prefix': 'comm'
'body': """
<div class="${1:classes}">
${2:<!-- your markup here -->}
</div><!-- ${1:classes} -->
"""
Or more advanced:
'.text.html':
'div+comment':
'prefix': 'comm'
'body': """
<${1:div} ${2:class="${3:classes}"}>
${4:<!-- your markup here -->}
</${1:div}>${2:<!-- ${3:classes} -->}
"""
Save this file as (e.g. comm.cson) and put it in the packages directory.
Related
I am trying to include HTML tags in groovy code, My requirement is to add something like -- thanks and regards (in one line), in next line a image, followed by name (in new line), kindly let me know how I can achieve this.
I have tried below and it didn't worked.
body: """
Approval is required. Please provide acceptance \n
Visit the below link to approval/decline \n\n
Note This is system generated email
""" + ''' </p><p Regards,</p>src="<image path>" alt="yes"><br><br><b><span
Cloud></b></span><br>myname<br></p>''', mimeType: 'text/html'
Are you aware of the Groovy MarkupBuilder (https://docs.groovy-lang.org/latest/html/api/groovy/xml/MarkupBuilder.html)?
I would solve your question like:
def writer = new StringWriter()
def markup = new groovy.xml.MarkupBuilder(writer)
markup.html {
head {
title('Approval')
}
body {
mkp.yieldUnescaped('Approval is required. Please provide acceptance<br/>Visit the below link to approval/decline<br/><br/>Note This is system generated email')
p ('Regards,')
img(alt: 'your alt text', src: 'your image url')
p ('YamunaS')
}
}
writer.toString()
Which would result in:
<html>
<head>
<title>Approval</title>
</head>
<body>Approval is required. Please provide acceptance<br/>Visit the below link to approval/decline<br/><br/>Note This is system generated email
<p>Regards,</p>
<img alt='your alt text' src='your image url' />
<p>YamunaS</p>
</body>
</html>
And then rendered:
If you want to put the first sentences/lines into a paragraph or div container as well, just follow above way. A div-container would open a new closure again. For a full example including some stylesheets you can also have a look in one of my examples. It generates html dynamically and uses it in context of Springboot (which is probably too much for you now)
what is the correct way to display the tag name on the tag specific page and a link to it in Modx revo using tagLister? e,g, a post has tags Tag1, Tag2 and Tag3. Now you click on one of the tags and it brings to the target resource displaying al posts with that single tag. What code to put in that target resource so it shows that the user has landed on the specific single tag page. I want to display the name and the link of that exact single tag.
My tags target resource is the main blog resource: Here is the code:
<section>
[[The Code to Display the Tag name to put here]]
[[!getResourcesTag#Blog Pagination Hy?
&elementClass=`modSnippet`
&element=`getResources`
&tpl=`Blog Post on Blog Page`
&hideContainers=`0`
&pageVarKey=`page`
&parents=`[[*id]]`
&limit=`3`
&includeTVs=`1`
&includeContent=`1`
&cache=`0`
]]
<div class="PaginationContainer">
<span class="TotalPages">p [[+page]] (total. [[+pageCount]])</span>
<ul>
[[!+page.nav]]
</ul>
</div>
</section>
is it possible at all?
Finally found on the web.
If you got better solution, please put it here.
So the idea is to make a snippet which gets the tag and call the snippet where we want.
Step by Step.
Step 1. Make a new snippet and name it something, e.g. Tag Name,
Step 2. Put the snippet code in the snippet code placeholder,
Snippet code:
//-- Get all request string key/value pairs
$s = $_REQUEST;
if($s['key'] == 'tags'){
return $s['tag'];
} else {
return false;
}
Step 3. Call the snippet where you want the tag nam to show up, e.g. [[!Tag Name]]
It will show up the tag name on tag pages only.
Here is where I found it
https://forums.modx.com/thread/11108/dynamically-generated-list-of-documents-that-are-tagged-with-categories?page=2#dis-post-397237
I've two problems with my simple application.
I've read the documents twice, but had no luck to using boss_csrf_filter and passing variables to templates.
First I've done the configuration for using CSRF filter in boss.config file as the following :
{controller_filter_config, [boss_csrf_filter]},
{session_adapter, mock},
{session_key, "_myapp_session"},
{session_exp_time, 525600},
{session_cookie_http_only, false},
{session_cookie_secure, false},
{session_domain, ".myappdomain.com"},
Then, I've add to variable in template (which is under src/view/world/hello.html)
<div class="row">
<div class="12u">
<textarea name="message" id="message" placeholder="placeholder" required></textarea>
{{ csrf_token }}
</div>
</div>
Everthing seems fine, but no any hidden input element appearing. Should I check/configure anything else?
The second problem is with my app is passing variables to templates. My is controller something like the following code :
-module(myapp_world_controller, [Req]).
-compile(export_all).
hello('GET', []) ->
{ok, [{world}]}.
postcontact('POST', []) ->
{redirect, "/",[{contactformsend, "ok"}]}.
The code is redirecting without any value. So, the following code is not working (the same template file with I've mentioned above) :
{% if contactformsend %}
<script>
alert("Hi there is!");
</script>
{% endif %}
What I am doing wrong? How can I fix the problems?
I would propose to split your question into two, because I have answer only for the second part. When you use redirect in controller, you don't pass the variables. In the docs you can read this:
{redirect, Location, Headers::proplist()}
So the third argument is list of headers, not variables passed to templates. It makes sense: the variables will be taken from the controller, that is responsible for rendering "/".
The standard output of a tt_news list view hyperlink is like:
News Headline
How to remove the title tag from the standard output with typoscript ? So that you get:
News Headline
I' am looking for a typoscript something like:
plugin.tt_news.displayList.linkParams.ATagParams >
Info: The template (sub)marker which includes the hyperlink is called:
<!-- ###LINK_ITEM### -->
... some Headline ...
<!-- ###LINK_ITEM### -->
There is a hook for this.
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tt_news']['getSingleViewLinkHook']
You will have to use it in an own extension.
Your hook consuming class will have to implement the following method
function processSingleViewLink(&$linkWrap, $url, &$params, &$pObj) {
// modify $linkWrap to remove title="" using regex
[...]
}
See here for reference how to consume hooks in TYPO3: http://typo3.org/documentation/article/how-to-use-existing-hooks-in-your-own-extension/
It's
plugin.tt_news.displayList.linkTitleField =
However title will be there, it will not be filled.
If you want to remove the empty title part as well you need to dive into the plugin to remove it.
I want to parse a part of html page, say
my_string = """
<p>Some text. Some text. Some text. Some text. Some text. Some text.
Link1
Link2
</p>
<img src="image.png" />
<p>One more paragraph</p>
"""
I pass this string to BeautifulSoup:
soup = BeautifulSoup(my_string)
# add rel="nofollow" to <a> tags
# return comment to the template
But during parsing BeautifulSoup adds <html>,<head> and <body> tags (if using lxml or html5lib parsers), and I don't need those in my code. The only way I've found up to now to avoid this is to use html.parser.
I wonder if there is a way to get rid of redundant tags using lxml - the quickest parser.
UPDATE
Originally my question was asked incorrectly. Now I removed <div> wrapper from my example, since common user does not use this tag. For this reason we cannot use .extract() method to get rid of <html>, <head> and <body> tags.
Use
soup.body.renderContents()
lxml will always add those tags, but you can use Tag.extract() to remove your <div> tag from inside them:
comment = soup.body.div.extract()
I could solve the problem using .contents property:
try:
children = soup.body.contents
string = ''
for child in children:
string += str(item)
return string
except AttributeError:
return str(soup)
I think that ''.join(soup.body.contents) would be more neat list to string converting, but this does not work and I get
TypeError: sequence item 0: expected string, Tag found