Snippet Expanding Variables

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Jontu Kontar
Posts: 2
Last visit: Fri Jan 26, 2024 2:15 pm

Snippet Expanding Variables

Post by Jontu Kontar »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio 2022, 5.8.208
Operating system: Windows 10 Pro for Workstations
PowerShell version(s): 7.2.5, 5.1.19041.1682

*** Please add details and screenshots as needed below. ***

I'm working on setting up some templates that I typically use to make scripts and I'm a bit stuck on variables in snippets.

I've got a variable made called $FunctionName$ and the initial instance of it works as expected.

Later on in the script, I mash together $FunctionName$ and 'Block'.

e.g.

Code: Select all

        $FunctionName$ = 'Hello'; 
        $$FunctionName$ + Block = $HelloBlock
How do I encode that into a snippet?

FYI: In VS Code, it looks like...

Code: Select all

        ${1:<FunctionName>} = 'Hello'
        $${1:<FunctionName>}Block = $HelloBlock
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: Snippet Expanding Variables

Post by brittneyr »

We are not quite sure what you are trying to accomplish. Are you referring to the Snippet Editor?

Can you post the snippet file here:
https://www.sapien.com/support/upload
Brittney
SAPIEN Technologies, Inc.
Jontu Kontar
Posts: 2
Last visit: Fri Jan 26, 2024 2:15 pm

Re: Snippet Expanding Variables

Post by Jontu Kontar »

Yes.

I'm trying to setup a code template that I use. With VS Code, I can type in the name of the function and it will duplicate the name to various places in the script with some additional characters to indicate what it is.

e.g.
  1. function helloWorld () {
  2.  
  3. [ScriptBlock]$helloWorldBlock{}
  4.  
  5. $helloWorldJob
  6.  
  7. }
Is it possible to replicate that with the snippet editor?

Apparently, the forum software doesn't like powershell attachments and I can't put in pastebin links... Ok.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: Snippet Expanding Variables

Post by brittneyr »

PowerShell Studio's snippets do not support this behavior.

You are welcome to put in a feature request and we will see what we can do:
https://www.sapien.com/requests
Brittney
SAPIEN Technologies, Inc.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.