Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

If I want to assign a regular placeholder as a string, it's very easy: (anything the user types in will automatically be given quotes around it, so when they evaluate the cell str is a string)

 str = "\[Placeholder]"

I just can't get quotes around a named placeholder (not while assigning to a variable, at least):

 str2 = {"\"", Placeholder[ProjectName], "\""}

Any help would be appreciated, thanks in advance!

share|improve this question
    
I've got it, apologies for the self-answered post. It was treating the "=" as a string that caught me off guard. MakeBoxes[string ], RowBox[{"=", "\"", ToBoxes@Placeholder[enter here], "\""}] –  user15921 Jun 17 at 14:10
    
Please answer your own question if you found the answer :) –  Öskå Jun 17 at 14:16
    
I can't yet, too few rep :( If you'd like, take it and answer in my stead! –  user15921 Jun 17 at 14:31
    
How about now? 6 rep should be enough.. :) –  Öskå Jun 17 at 14:32
    
Thank you very much! Unfortunately, "Users with less than 10 reputation can't answer their own question for 8 hours after asking. " –  user15921 Jun 17 at 14:35

2 Answers 2

It was treating the "=" as a string that caught me off guard.

NotebookWrite[InputNotebook[], 
  Cell[BoxData[
   RowBox[{MakeBoxes[string], 
     RowBox[{"=", "\"", ToBoxes@Placeholder[enter here], "\""}]
   }] 
  ]]
 ]

Mathematica graphics

share|improve this answer
    
Even if your code helped you to answer your own question, it doesn't seem to work for me. Can you please fix it? –  Öskå Jun 17 at 16:38
    
Sorry, I'll add full context. In my own code this is written to a new notebook, where the user fills in the placeholder and evaluates to save their input as the variable string. –  user15921 Jun 17 at 18:39

Maybe this can help you:

x = "";
InputField[Dynamic@x, String, ContinuousAction -> True]
Dynamic@InputForm@x
share|improve this answer
1  
Appending FieldHint -> "Enter Project Name", FieldHintStyle -> Red would make your answer, which is nice, nicer :) –  eldo Jun 17 at 22:09
    
This is pretty spiffy, thanks! I like the aesthetics of the InputFields, but I think placeholders are better for 'savability'; if you fill them out and save the nb the code stays, but with input forms if you close the kernel, you loose what you've typed in. –  user15921 Jun 18 at 12:54
    
@user15921 well, sure context matters here :) –  Kuba Jun 18 at 18:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.